Generating BodyForce values based on Orientation?

I have a function that takes in the Y Orientation of a part. This function needs to take that number and translate it into a Vector3 value that a BodyForce can use to move a player in the direction the part is facing.

For example, if the BodyForce has a total of 10,000 units to distribute between the X and Z axes and the part’s orientation is 0, it needs to set the Z axis of the BodyForce to 10,000. An orientation of 180 would produce -10,000 on the Z axis. An orientation of -90 would produce -10,000 on the X, while 90 would produce 10,000 on the X axis. Any orientation between these values would need to split the 10,000 between the X and Z axes.

I’m sure there is a mathematical function that can calculate this, but I can’t figure it out - how could I do this?

1 Like

It’s possible to use the LookVector of the part’s CFrame to do exactly what’re you trying to do, in a simpler way, if I understood the post correctly:

BodyForce.Force = Part.CFrame.LookVector * 25 -- this number is the velocity

Just incase you don’t know what LookVector is, it’s a vector that represents the direction the front face of the part is pointed at.

Hey, I tried setting the Force to the LookVector of the bouncer part, but it doesn’t actually seem to do anything. The code is working, because the sound plays and the console outputs appear, but the player isn’t moved at all. Any suggestions?

You can try something like
BodyForce.Force = Vector3.new(math.sin(yOrientation), 0, math.cos(yOrientation).Unit * 10000

With a y orientation of 0, it returns 0,0,10000
With a y orientation of math.pi (180 degrees), it returns 0, 0, -10000

You may need to increase the force quite a bit, characters are designed in a way so they resist forces on them.