BodyGyro CFraming Help

So I have a VehicleSeat and when you press W, it rotates forward, and when you press S, it rotates backwards. However, it’s rotating using global space rather than object space, so if I change the orientation of the seat, it rotates the same way every time, regardless of the orientation. I’m trying to make it so it rotates forward in the direction where the VehicleSeat is facing.

This is how I would like it to look regardless of the seat’s orientation:
https://gyazo.com/6c5d0b27500969d9ca39cf2d59a46707

How can I fix this? Here’s the line of code I’m using:

BodyGyro.CFrame = BodyGyro.CFrame * CFrame.Angles(math.pi/6, 0, 0)
2 Likes

Please show us how it rotates when it’s oriented a different way. It’s not clear what you mean.

BodyGyro.CFrame = CFrame.new(Seat.Position, (Seat.CFrame * CFrame.Angles(math.pi/6, 0, 0) * CFrame.new(0, 0, -10)).Position)

I’m not an expert at using BodyGyro but try this.

You should store an untouched value of the Seat’s CFrame if you want to restore to normal orientation

It rotates in the same direction regardless of the seat orientation.

https://gyazo.com/31a2d7fcba7023f90ca77fb1bbde5b02

Unfortunately, that didn’t fix the issue and is still causing the same result.

Can’t you use normal tweening? Or use TweenService?
I’ve personally never liked BodyGyro because of how weird it is to make it work.

The issue isn’t the method of which the CFrame is being set. Changing to TweenService wouldn’t solve the issue, because the CFrame would still be modified in world space.

I’m trying to have a crack at this issue but I hate CFrames and can’t quite figure it out. I’m trying to implement CFrame:ToObjectSpace in my code, though I don’t think I’m using it properly.

BodyGyro.CFrame = CFrame:ToObjectSpace(BodyGyro.CFrame) * CFrame.Angles(math.pi/6, 0, 0)
-- It looked something like this. Can't remember what my repro looked like.

Yeah, I’m getting this error:

attempt to call method ‘toObjectSpace’ (a nil value)

1 Like

What you need to be doing is something like this

BodyGyro.CFrame = Part.CFrame:ToObjectSpace(BodyGyro.CFrame) * CFrame.Angles(math.pi/6, 0, 0)

Where Part is your VehicleSeat.

What this basically does is convert the BodyGyro.CFrame to a CFrame relative to the Part, using :ToObjectSpace(), and then applies the rotation.
Hopefully this should work