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?
--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
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.