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.