#Diagonal movement keeps velocity after changing input to one direction

1 messages · Page 1 of 1 (latest)

frigid dragon
#

How could I fix the fact that when going diagonally then releasing side (or forward) inputs to go into one direction, it still sort of slides along the diagonal direction?

velocity.x = move_toward(velocity.x, direction.x * SPEED, ACCEL*delta*absf(direction.x))
velocity.z = move_toward(velocity.z, direction.z * SPEED, ACCEL*delta*absf(direction.z))

I know that the bug happens because of absf(direction.#), but it is crucial for another bug/issue.

https://vimeo.com/992185619?share=copy

This is "Diagonal bug" by yes yes on Vimeo, the home for high quality videos and the people who love them.

▶ Play video
frigid dragon
#

Solved by doing this:

var new_velocity = Vector3(velocity.x,0,velocity.z)
new_velocity = new_velocity.move_toward(direction * SPEED, ACCEL*delta)
velocity.x = new_velocity.x
velocity.z = new_velocity.z