How to make character face the direction of its velocity while falling?

In my game, the character can dive by pressing a key, which applies a velocity to their HumanoidRootPart using UpVector and LookVector.

What would be the best way to get the character to face the direction of its movement (e.g. tilt upwards when going up and tilt downwards when falling), without affecting the movement?

The current dive

2 Likes

Use CFrame.lookAt(Vector3.zero, lookVector, upVector), which will give you a world space vector that points in the direction of lookVector.

1 Like

Here’s what I wrote:

--hRP is HumanoidRootPart
if Humanoid.FloorMaterial == Enum.Material.Air then
	repeat
		hRP.CFrame = CFrame.lookAt(hRP.Position, hRP.CFrame.LookVector, hRP.CFrame.UpVector)
		wait()
	until Humanoid.FloorMaterial ~= Enum.Material.Air
end

It just points the player at the world origin. Is the LookVector put in wrong, so the origin is the default?

LookVector has to do with current direction not velocity. You need to use the hRP position plus the velocity to get a point in the direction the hRP is moving. This will try to point the -Z axis in that direction though, so you will also need to rotate around the X axis afterwards, such as with CFrame.fromAxisAngle

1 Like

CFrame.new(Vector3.zero, velocity) * CFrame.new(hrp.Position). Hrp is HumanoidRootPart and velocity is HumanoidRootPart velocity.

1 Like

Ok, I changed it to

hRP.CFrame = CFrame.lookAt(hRP.Position, hRP.Position + hRP.Velocity, hRP.CFrame.UpVector`)

and while it does kinda work, it’s flickering the rotation as well. Also, after touching a wall, instead of stopping like before, it changes direction, and can get stuck. I’ll try to work it out myself, but I’m new to this stuff and probably won’t be able to.

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