Bouncing ball stops when hitting edge of platform

Hi all,

I am having an issue with a bouncing ball game I’m trying to create. The ball can fit through a hole in the platform it’s bouncing on (the user can move platforms left and right), but if the ball bounces near to the edge of the platform, it can start bouncing lower and eventually stop.

I’d like the ball to always bounce to the same height regardless of where it hits the platform but I can’t seem to figure this one out! Any help greatly appreciated.

Here is a link to a gif showing what is happening at the minute:

this should work:

void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    void OnCollisionEnter(Collision collision)
    {
        rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
        rb.velocity = rb.velocity = new Vector3(rb.velocity.x, 10, rb.velocity.z);
    }

since it resets the ball’s y velocity every time it lands on the ground and accelerates it the same amount every time. Just make sure the ball has a Rigidbody component.

I hope this helped!

Thanks @TheEmeraldRuby , I tried your code but I can’t seem to get it to work right - it makes the ball bounce way above the platform, like it’s bouncing on an invisible platform.

I think the answer could be in that OnCollisionEnter method though so I will keep playing around with that.