LinearVelocity dash direction

So the LinearVelocity dashes in the correct direction, however I can’t seem to get the player to face in the direction they are dodging.

Here is the code for facing the character:

HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position, Vector3.new(DodgeVelocity.X, 0, DodgeVelocity.Y) * 1000)

And here is the code for getting the velocity direction:

function GetDodgeVelocity()
	local VectorMask = Vector3.new(1, 0, 1)
	local Direction = HumanoidRootPart.AssemblyLinearVelocity * VectorMask
	
	if (Direction.Magnitude <= 0.1) then
		
		Direction = CurrentCamera.CFrame.LookVector * VectorMask
		
	end
	Direction = Direction.Unit
	local VelocityDirection = Vector3.new(Direction.X, 0, Direction.Z)
	local DodgeVelocity = VelocityDirection * DodgeSpeed
	
	return DodgeVelocity
end

Here is en example of what I mean:
https://gyazo.com/6a938fee1ff58682a4443a3195932739

How would I get the player to face in the same direction as they are dashing?

1 Like

HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position) * CFrame.lookAt(Vector3.zero, DodgeVelocity*Vector3.new(1, 0, 1))

This will instantly snap the character’s look direction to match DodgeVelocity, but personally I’d use an AlignOrientation constraint instead of setting CFrame directly.

Also, CFrame.lookAt(Vector3.zero, Vector3.zero) gives NaNs, so you better check if DodgeVelocity’s Magnitude is > 0 before setting CFrame.

2 Likes

Thank you very much! I will defiantly look into using AlignOrientation instead.

1 Like

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