# Bounce behavior with gravity

Greetings,

I’m making a sloppy quick experiment to see if I can give the bounce behavior gravity, sort of making a bouncing ball

I got something to work at first, but I wanted to put everything into a function call instead to avoid copy pasting, and make it simpler to use (Old code still present for experimental purposes)

However, now I think I messed something up. When the balls bounce on the ground, they just start bouncing slightly higher with each bounce…

Can I adjust this to make sure the balls always bounce at the same height, or bounce lower instead?

I think the issue may be with the adding of a permanent force of 30 pixels at 90 degrees - the force applied in the repeat block and the force applied in the second to last event:

I believe this force accumulates. Should it be an instant force?

Unfortunately, switching them to instant forces completely breaks the gravity, so they have to be permanent.
The strange thing is that this was working just the way I wanted it to before I converted it into a function, and I’m trying to see if I can roll back to that version, and why the function doesn’t work
(And yes, I’m disabling one or the other before I test each one)
Is there something else I’m probably missing?

Alright, since I was originally doing this in the browser version, I decided to remake it in the desktop version, retracing my steps:

This is what it looks like currently:

See how the balls are bouncing higher and higher each time? Yeah, I want to have the opposite of that, or to just keep them bouncing at the same height.
I swear I had a working version of this before, but now it’s not working out…

Also, here’s what it looks like with instant forces for the gravity instead:

The balls aren’t being affected by gravity at all, not what I want.
Can someone please shine some light on this to see what’s wrong?

It’s an interesting concept. A sort of lightweight physics.

Let me see if I understand what’s happening. It’s applying a continuous downward force (90°) When applied continuously it will slowly cancel out upward momentum and change it to a downward force. The problem is the force is probably adding more force when it’s dropping. The realworld has friction, wind resistant and energy loss when it hits a surface. Objects also have a maximum speed that they can reach (Terminal velocity) The longer it drops, the more downward force it get.

You need something to slow down the object. A perfect spot would be within the bouce behavior. The bounce behavior saves the velocity and then reapplies it in another direction. It might work if the behavior slowly decreased the old velocity until it reached zero.

I’m not sure how to do it outside of the bounce behavior. The point of collision is just the perfect time and place for it.

Okay, I initially thought this was going to be a nightmare to try and remedy, tampering with the ready made example, but after one test run, I got it to work pretty good! The balls aren’t bouncing around to the ceiling anymore!

The results aren’t the most consistent, the ball varies in bounce height a teeny tiny bit, but it’s barely noticeable, so it’ll work for me.

Also, I had to copy the code and add a variable check, but what I have worked out. I’m surprised it was so easy.

Here, I added a boolean check to see if the object has a variable picked. This is to prevent the no-gravity bouncing behavior from breaking in case I need it elsewhere

So now I can have bouncing objects with AND without gravity. This just solved two of my problems in one!