How to keep a ball bounce with a constant speed?

I need a way to keep a ball that bounces on the floor bounce with a constant speed, the bounciness is set to ‘1’ and the friction is set to ‘0’.

Is there a ‘roof’ or gravity involved? I’m trying to grasp what you want to see happen and what’s involved.

Yes, there is roof and gravity

Okay… so you want it to bounce between the top “roof” and the bottom “Ground/floor” … bounciness = 1 and no friction sound good, but if the object is affected by gravity (just thinking out loud here), then that would prevent what you’re desired behaviour, I would think. Right?
How does it look if you disable gravity on the ball itself?

The ball just stands where it is

Yep, err… lol (my bad!) Okay, of course you just have to give it a little gentle touch to get it going lol.
Set its velocity to a value or addforce to it (because now it won’t move at the start because it doesn’t fall) :slight_smile:

Which value do you recommend for the speed?

Anything just to get it going try whatever you think. You can always change it.
Any value should give you a sense of whether this is doing what you’re hoping for.

private Vector2 v;
    // Use this for initialization
    void Start () {
       
    }
   
    // Update is called once per frame
    void Update () {
        v = new Vector2(0, 2);
        GetComponent<Rigidbody2D>().AddForce(v);
    }

The ball keeps accelerating when it hits the walls

yes, just move that to start (only need to set it once, I think, with addforce in your scenario).

Didn’t help the ball gets faster each time it hits the walls

okay, just for peace of mind if you set velocity instead of addforce (set like 1 or something just to start) does it still accumulate speed?

Yep

Okay… So I tested some things out :slight_smile: I’ll be right back after i complete a minute more or so. I think i have it working

Does it work ?

Here’s what I got/did: AddForce of 300 (?! lol) gave me +/- 6 (depending on the direction, but it was constant.
velocity set to 3 gave me +/- 3 (much simpler to follow for me)
I made 2 materials, one for the wall & one for the ball, but later ended up making their settings the same.
So, make 1 material … bounciness = 1, drag all off (make sure ball’s rigidbody drag is also off)
and I set the bounce combine to “maximum” but I doubt that matters now that they all have the same value.

Yep try what I said and let me know what results you get :slight_smile:

For completeness’ sake, my sphere was set to have a mass of ‘1’. And if the force/velocity I applied was smaller than (whatever threshold), though the ball would move, upon contact (regardless of bounciness, etc), it would freeze at the wall… not bounce [back].

Didn’t understand the lines I bolded

Okay. If you right-click down in your assets area, like where scripts are made, etc… You see a list of options.
Go to the ‘create’ menu and look for “Physics Material” & make one of those.
then you’ll see what I mean. Once you’ve set its settings, select your walls + ball and drag the physics material into their colliders. (it accepts a physics material there).
:slight_smile:

1 Like