Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would I make a block temporarily "target" a player by setting a velocity?

Asked by
RoboFrog 400 Moderation Voter
10 years ago

Long title aside, I'm trying to make a block that when you step on a button, it Cframes itself out a bit (already coded), and "launches" itself at the player. I would like to accomplish this by using a one-time set velocity, meaning the player can dodge it if they're quick enough, and it won't keep targeting them if they move.

As you can see by my decent rep, I'm not requesting a script, I'm mostly looking for information on how to even accomplish this.

What I've tried so far --

  • Creating a script that, when the player's state is changed, it checks their head's position and then sets that as a CFrame value (of which I know very little about) inside of server storage. The value of the CFrame value is then set as the block's velocity whenever the player touches the button.

    • This, of course, isn't working. I realize it sounds easier to just code the velocity relative to the button, but I plan on making the flung object random, and the button itself is more comparable to a floor.

    • I don't even believe setting the head's position to the velocity would work correctly, since it largely functions like a TranslateBy.

If you know another method, or a way to "repair" the method stated above, I would love to know. It's probably clearly evident that this is one of my lesser zones of RBX.Lua.

1 answer

Log in to vote
1
Answered by 10 years ago

Well there is a GameObject called RocketPropulsion.

It is inserted into a part, and has 3 properties and a function that is normally used for this.

The properties are MaxThrust,MaxSpeed,Target, and its main function is :fire(). I'm pretty sure you could guess what the properties mean (but you'll need to set the target in a script.) The function basically tells the RocketPropulsion object to start heading towards its target (so the gameobject could exist in the brick, but it does not have to head towards it's target.) There is also an aesthetic property called CartoonFactor, which basically causes the part to face towards its target. I would try to use this by firing the :fire() function, then create a BodyForce equal to the current velocity of the part. Then I would call the :abort() function (which basically stops the rocket from heading towards its target, and it stops adding force to the part which is why you need to create a new BodyForce so the brick doesn't just stop) so that the part keeps moving in the same direction. Do not downvote this if it doesn't work because it is just an idea and I haven't tried it myself.

1
Don't worry, I'd have no reason to downvote; even if an idea doesn't fully work, it lets me know about new things to try. I've not yet had the time, but will be implementing this system tonight. I'll get back to you with the results! RoboFrog 400 — 10y
1
Alright, I just tried it, and it mostly worked for the purposes needed! Instead of using BodyForce (since RocketPropulsion doesn't change velocity), I instead used the line "script.Parent.Velocity = script.Parent.CFrame.lookVector * 40" to achieve the desired effect. Thank you for the help! RoboFrog 400 — 10y
0
Your welcome. Also thank you for teaching me how you did it too! Octillerysnacker 115 — 10y
Ad

Answer this question