How can I know the velocity that my ball loses when it bounces a wall?

Godot Version

Godot 4


That’s my ball’s rigidbody configuration

My wall is a staticbody and it doesn’t a material
I want to predict my ball’s future position and I want to consider bouncing but I need to know how much velocity my ball loses when it bounces with a wall
Is that information enough?
Thanks for your time

You need to know the how the bounce parameter calculated the absorption. But if your bounce is 1 it shouldn’t loose any. it I’ll just be the normal of the surface and the reflection of the velocity vectors.

Why not just query the velocity after a collision?

Thank you for your answer. Despite setting the bounce parameter to 1, my ball still loses velocity. I have checked the velocity after each collision, but the difference between the velocity before and after is not consistent in every case.
Can I give you more information?

Sure, I’m also wondering if the friction factor is causing some loss. But we can also look at the source code.

1 Like

This is the code where I calculate the future position of the ball when bouncing but I don’t think it will help.

func FuturePositionBounce():
	var collisionPoint=ball.ball_ray_cast.get_collision_point()
	var ballVelocityNormalized=hypotenuseNormalized(ball.linear_velocity)
	# Collision Point To Ball Position Magnitude
	var CPTBPM = GetMagnitude(ball.position-collisionPoint)
	# The remaining part of the raycast after the wall
	var magnitudeRemaining=GetMagnitude(ball.ball_ray_cast.target_position)-CPTBPM
	var wallNormal= ball.ball_ray_cast.get_collision_normal()
	var unitVector = GetOpositeUnitVector(ballVelocityNormalized,wallNormal)
	var localballFP=collisionPoint+unitVector*magnitudeRemaining
	return localballFP
func GetOpositeUnitVector(ballVelocityNormalized,wallNormal):
	if wallNormal.x==1:
		return ballVelocityNormalized
	elif wallNormal.x==-1:
		return ballVelocityNormalized
	elif wallNormal.y==1:
		return ballVelocityNormalized
	elif wallNormal.y==-1:
		return ballVelocityNormalized

It works but is very vague and I guess that’s because of the ball’s velocity deceleration

What is this? Does normalized() not work in this case?

What if wall isn’t completely “square” And all iff statements fail?

This seems very complicated. Anyway this isn’t about your prediction this is about the physics engine absorbing energy on the bounce.

Does your wall have a physics material?

Looking at the physics code a friction value will effect the normal impulse of colliding Bodies.

# This function gets a unit vector from a vector that in this case is ball.linear_velocity

The walls are completely “square”.
Anyways, you are right, this is not relevant for the problem right now.

My walls don’t have a physics material. They are just staticbodies with the default configuration.

Okay even if the static body doesn’t have a physics material, the code will pull, what I assume, a default friction to do the friction calculation. Maybe you should add a physics material on the wall with the friction set to 1. (Or zero I don’t have a computer nearby)

the friction calculation takes the minimum friction value between the two bodies. So if the default is less than one it will reduce the normal impulse of the bounce. (I think)

Yea just set the wall friction to zero.