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

How to make something lean in the direction of it's velocity?

I've been trying to do this since yesterday. I'm getting the velocity of the character every frame and lerping their RootJoint's C1 property. Here's the code:

RS.Heartbeat:Connect(function()
	velocity = root.Velocity
	RootJoint.C1 = RootJoint.C1:Lerp(CFrame.Angles(math.rad(velocity.x),math.rad(velocity.z),0),.1)
end)

And here's a clip of what happens...https://gyazo.com/3df62020253b66cab126a8bdde130c20

So yeah, it turns me into a spaceship. I don't know how to fix that. I tried multiplying by the RootJoint's base value instead of its current value and that led to some odd behavior as well. Didn't work. Also, you can see that the leaning isn't consistent. Depending on which way I'm facing, it changes. I really have no idea how I can do this, so any help is appreciated!

Edit: It no longer makes me a spaceship, I fixed that. But the leaning still isn't relative. https://gyazo.com/9c21ad7b23f95b5a1de04cba41a40642

1 answer

✓ Accepted answer

you can use velocity relative to the HumanoidRootPart's cframe instead of just regular velocity

velocity = root.CFrame:VectorToObjectSpace(root.Velocity) -- if you're wondering why i'm using VectorToObjectSpace instead of PointToObjectSpace or just plain ToObjectSpace here, it's because VectorToObjectSpace only considers the rotation of the cframe, not its position

you might have to switch around x and z but it should rotate relative to the character's orientation

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