Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by
Elyzzia 1294 Moderation Voter
4 years ago

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

Ad

Answer this question