BodyGyro Object Space CFraming?

I need to make a part tilt forward relative to its Object Space, so I will be using BodyGyro’s CFrame property.

The problem is if I do this, then it’s relative to World Space.

BGyro.CFrame = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0,0,math.rad(20))

image

And if I do it like this, then it will be Object Space, except I need it so that if I call it multiple times it is still rotated only 20 degrees. The big issue here is the * CFrame.fromEulerAngles keeps adding degrees, I want it so that it sets the degree of the CFrame.

BGyro.CFrame = Part.CFrame * CFrame.fromEulerAngles`XYZ(0,0,math.rad(20))

image

This issue should be quite easy to resolve, but I have barely used BodyGyros and don’t know the best way to deal with their CFrames.

BGyro.CFrame = Part.CFrame * CFrame.Angles(0,0,math.rad(20))

This might work.

This does work in Object Space, but the problem is that I need to make it so where it sets that as the CFrame’s Rotation, because I have a loop that calls it multiple times, and I need to make sure that the degress is not over 20. I need to make sure that each time it sets it to 20 and not over. So * CFrame.Angles and * CFrame.fromEulerAngles doesn’t appear to work in this scenario.

1 Like
local OriginalCF = Part.CFrame

BGyro.CFrame = OriginalCF * CFrame.Angles(0,0,math.rad(20))

image
When I go East, the boat / part is perfectly fine, this is exactly how I want it to tilt on all directions.

But even with your edits, once the boat turns to face the other direction, It tilts the wrong way
image
It should be tilting up from the front. But as seen in the second picture it is still tilting sideways.

Try this:

local Original = Part.CFrame

BGyro.CFrame = Original * CFrame.new(math.rad(20)*math.clamp(Part.Velocity.X,0,1),0,math.rad(20)*math.clamp(Part.Velocity.Z,0,1))

What is that supposed to do? It doesn’t look like that sets the Rotation part of the BodyGyro?

It should work

Wait, hold on, let me edit it to clamp for a second

Alright, try that.

It might work

It should tilt it depending on its velocity.

This will not work. Velocity is not relevant and you are composing a non-oriented CFrame onto the existing Gyro CFrame which will have no effect on the rotation it produces.

@Beartikal I would recommend that you have a read about AlignOrientation, a non-legacy constraint object which will let you achieve what you want without having to do any maths at run-time.

2 Likes

He’s trying to make it tilt backward dépendant on which direction it’s moving.

I will make it match the orientation of a non-active part. I will try that. Thanks.