Dash mechanic that follows terrain's slope

My current dash mechanic is pretty typical, I simply parent a LinearVelocity\BodyVelocity inside the character’s RootPart when the player presses the dash button. It works pretty well, however I have these issues:

As you can see the character jumps over the terrain whenever there is a slope, which is not really what I’m looking for. So I was wondering if there was a way to make a dash mechanic that follows the terrain slope without making the character jump over it.

In reverse, if the character is trying to walk over a slope, the dash will be much slower and get stuck.

I’ve tried using the Humanoid:MoveTo(vector3) method, and it works okay-ish but I’m not 100% satisfied because the player can cancel the dash by moving & in order to simulate speed, I have to increase the WalkSpeed of the humanoid, which is something I’d rather avoid doing since it might interfere with my game’s modifiers and such.

I think a possible solution could include raycasting, but not sure on how it could work. Perhaps I project a ray in front of the character, whose lenght matches the distance of the dash, then i project a few extra rays vertically starting from the main ray so I can determine if there is a slope? It can work with the first problem, but not so much with the second.

Thanks to those who can help!

I think you could cross the HumanoidRootPart’s rightvector and the surface’s normal to get the direction the slope is going in every frame. Then use that direction as the force’s direction?

Like this:

local ForceDirection = HumanoidRootPart.CFrame.LookVector
local Ray = workspace:Raycast(HumanoidRootPart.Position, Vector3.new(0, -5, 0), Parameters)
		
if Ray then
	ForceDirection = Ray.Normal:Cross(HumanoidRootPart.CFrame.RightVector)
end
		
Linear.VectorVelocity = ForceDirection * IMPULSE_FORCE
1 Like

Ah, thank you! I’ll try this and let you know. And yeah, I should’ve probably considered using normals lol

Would you suggest using RunService to update the LinearVelocity every frame?

2 Likes

Yeah, I tested a demo and that’s pretty much how I did it

1 Like