Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I apply BodyVelocity to an object based on it's local orientation?

I need to apply Velocity to a ship based on it's local rotation. My only issue is that the methods that I have tried so far fail in one area: When more then one rotational axis has force applied to it she ship rotates on another axis,

Eg if the X and Y rotational axis both have force applied to them, the Z axis starts rotating as well. Is there any way to fix this?

(if it helps at all I am trying to make a space craft move based on it's rotation applied from a BodyAngularVelocity bodymover)

1 answer

BodyGyro objects are great for maintaining orientation. Give their CFrame property this constructor:

BodyGyro.CFrame = CFrame.new( [Vector3]Origin, [Vector3]Focus )

As for figuring the direction to apply force, use this formula:

local p = workspace.Part;
local power = 100;

p.BodyVelocity.Velocity = p.CFrame.lookVector * power;

2 comments

0

So origin should be the base part position, but what should focus be?

0

wherever you want your craft to be looking man

This discussion is preserved as it was. New answers, comments, and votes are closed.