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.
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.