Bouncing ball that keeps the same height

Hi, new to Unity and these forums and any help is appreciated.

I am looking to create a bouncing ball that always keeps the same height and speed, no matter what it hits. I currently have the ball bouncing around on the 2d plane. All surfaces have bouncy physics with no drag as well as the ball. The issues I have encountered are:

1 - The ball always gets more height with every bounce. I’ve tried playing with the ‘Bounciness’ setting of the Bouncy Material but .99 still bounces a little higher every hit and .98 seems to bounce a little lower every hit.

2 - When it collides with an object, it reacts with rigidbody and so will hit corners and bounce lower and faster in different directions. I need it to simply change direction with the same velocity and speed whenever it hits the side of an object or keep the same direction and still bounce to the same height it always did if it hits the top.

I hope you can help shed some light on methods to get these done.

Thanks,
Si

Hmm…

After tinkering with it some. I created a mathematical ball. It bounced and everything it needed to. What I did was to check to see if it hit something below it.

Vector3.Dot(Vector3.up, hit.normal) > 0.9f

If this was true, I simply made the velocity’s length what my bounce height was.

if(Vector3.Dot (Vector3.up, hit.normal) > 0.9f) velocity = velocity.normalized * bounce;

I do not know if this has an application to physics, but it should. OnCollisionEnter, check the normal, and see if that normal is pointing up, or close to it.

Thank you very much for the reply but I’m very new to Unity and would as that you explain in more detail the functions used and how to implement them properly.

I’m used to Visual Basic so this script is all very strange to me still. In VB I would be using “if shape.top + shape .height <= Image.top” etc. Is there not a way I could say:

On collision - if the bottom of the ball is lower than the top of the object it hits and the top is higher than the bottom then - change direction of the ball with the same velocity - else - (If the ball is higher than the object it hit) reverse the velocity of the bounce - so it keeps traveling the same x axis and still bounces to the same height as before. ?

Again thank you for your patience

Okay, after a few hours of playing around with different limitations to the physics of my rigidbody ball I still haven’t got anywhere. I’ve had many different results but none of them are what I’m after.
I’ve got everything I need in place except for the following.

I need to be able to control the x axis speed of the ball bouncing. So if it is higher than x then reduce it gradually until it becomes x again. I also need the same with height.
Ideally the height would be to register the height of the ball at ‘awake’ and then decrease height gradually if it is ever higher and increase gradually if it is ever lower.

Hope you can help,
Thanks.