Sudden surge in speed when colliding along a wall (3D)

Godot Version

4.2.1

Question

Whenever I use the slide I scripted (which simply makes friction and maximum speed smaller) and slide along a wall, the character suddenly speeds up.

The movement for slide looks like this:
velocity.x = move_toward(get_real_velocity().x, direction.x * SPEED, FRICTION * delta)
velocity.z = move_toward(get_real_velocity().z, direction.z * SPEED, FRICTION * delta)
where FRICTION = 10 and SPEED = 2 for slide.

Direction looks like this:
var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_back")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()

My test output at the time of sudden acceleration is as follows (the numbers after “ok” are the direction vector, the 0s and 1s are the collision from get_last_slide_collision().get_normal(), others are velocity from get_real_velocity()):

ok (-0.99936, 0, -0.035772)
(0, -0, 1)
(-13.19095, 0, 0)
ok (-0.99936, 0, -0.035772)
(0, -0, 1)
(-13.02428, 0, 0)
ok (-0.99936, 0, -0.035772)
(0, -0, 1)
(-12.85762, 0, 0)
ok (-0.99936, 0, -0.035772)
(0, -0, 1)
(-25.36623, 0, 0.071554)
ok (-0.99936, 0, -0.035772)
(0, -0, 1)
(-50.31299, 0, 0)
ok (-0.99936, 0, -0.035772)
(0, -0, 1)
(-50.14631, 0, -0.070782)
ok (-0.99936, 0, -0.035772)
(0, -0, 1)
(-77.8979, 0, 0.071039)

I think that it has something to do with the get_real_velocity().z balancing between positive and negative (like 0.071554 >> 0 >> -0.070782 >> 0.071039), since collision and direction didn’t change at all, but I can’t find the exact reason.

Why not just give the slide a physics material and set it to be whatever friction you want and stick the player on an object that slides down?

I don’t want the player to stick to the ground at all times, though, as I’m planning to use acceleration and the lack of friction to create slopes and slides the player can use.

Alright, I played a bit more with Player’s config. Changing the Safe Margin of CharacterBody3D from 0.001 to 0.005 fixed it!

1 Like