Kart Bouncing against walls. Vector3.bounce return unexpected high value

The reason for your problem is that the velocity of a colliding body is post-contact. This means that “straight collisions”, where the physics body is at a near stand-still, produce velocities that are small. On the contrary, oblique collisions barely affect the velocity of a moving physics body so the velocity maintains most of its length.

If you wish to bounce your vehicle based on the entry velocity, not the post-contact velocity, you have to store a velocity history.

var previous_velocity = Vector3.ZERO

func _physics_process(delta):
	# =================
	# === Your code ===
	# =================

	# [End of function]
	previous_velocity = velocity

It’s not bounce() returning a high value – it’s you multiplying the value by 25. Besides, bounce() doesn’t manipulate the length of the vector, it just computes its reflection vector for a given plane normal. Just don’t multiply by 25. You will find that using the previous_velocity, as outlined above, will yield better results.

In cases of inaccurate bounce directions

Depending on your turning speed and delta time of your physics, you may start to notice that previous_velocity does not correctly represent the body’s direction one tick later. That is, of course, because it’s an “old” value.

You can fix this by extrapolating the previous_velocity vector towards the current state of your body. An example of such extrapolation can be found here.


I hope that helps. Let me know if you have additional questions.

2 Likes