How to get the direction of a velocity using CFrame?

So, i’ve been trying to make so the player character tilts in the right/left direction, if they are only walking towards that direction. However, the issue is that, since its a Vector3, it wont align up with the player’s orientation, heres a short video

The way i made it tilt was relatively simple, took about 6 lines of code.

Also, root is the HumanoidRootPart.

local Xspeed = root.Velocity.X
if root.Velocity.X > root.Velocity.Z then
	Xspeed = root.Velocity.X
else
	Xspeed = 0
end
2 Likes
1 Like

The velocity property is a vector, and velocity vectors denote both direction and speed. The magnitude of the vector is the speed, with the components making up the direction. You can think of a velocity that is (0, 5, 0) as a movement towards the sky at 5 studs per second.
Rather than using the velocity to determine the move vector, you should use the movedirection property of the humanoid.

1 Like

I still don’t get it. I ended up with the same result as last time.

use humanoid.MoveDirection:Dot(humanoidRootPart.CFrame.RightVector)
it should give you a number -1 to 1 corresponding to left/right
i can explain the math further if u want

It worked, thanks! The first time i tried this method it wasn’t working, but then i realised what was the issue and i managed to fix it.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.