I am making a game where a ball bounces on bouncers. The ball goes up due to the bouncers and down due to the gravity. I use Physics 2. The restitution of the ball is 1.2. I want my app to create an object (in this case another bouncer) at the maximum height the ball can reach after colliding with a bouncer. I have two questions:
How can I do this? I know how to define the x-coordinate, but not how to define the y-coordinate.The speed of the ball in increases (in general) after each bounce, so the maximum height too.
How can I trigger this event only once per bouncer? (Current situation: the ball bounces on the same bouncer twice and creates two new bouncers, but I want to create one new bouncer no matter how many times the ball is colliding with the same bouncer.)
Thanks in advance!
Store current Y position of the ball in a variable, and update it as long as current Y is lower than stored value. This way, you’ll get the max height reached.
If necessary, reset the max height when colliding with a bouncer.
For the second point, assign a collided variable to the bouncer, change it to 1 when the ball bounces off it, and change it to 2 when a new bouncer is created. Then use that variable to decide if a bounce should produce a bouncer or not (if ball is colliding with bouncer and bouncer var collided is = 0 (or 1), change ball variable ActivateBouncerBuilding to 1)
But unfortunately it doesn’t work. It creates a new bouncer at the current Y position of the ball and it doesn’t create a bouncer at the max Y position the ball can reach directly after bouncing. Can you help me out? Thanks in advance, again!
Yes, I want to create a new bouncer (let’s say bouncer 2) at the moment the ball is colliding with bouncer 1. I want bouncer 2 to be created at the highest point the ball can reach after bouncing on bouncer 1. So somehow I need to define the maximum height the ball can reach after bouncing on bouncer 1, not the highest point the ball reached during the previous bounce. Thanks for helping me out.
Thanks! It works now for point 1, but triggering the ‘‘create bouncer event’’ only once per bouncer doesn’t work for me. The situation is still that the ball bounces on the same bouncer twice and creates two new bouncers, but not one new bouncer no matter how many times the ball is colliding with the same bouncer. Can you please give me some help on this. I tried variables but it doesn’t work. Any suggestions? I really appreciate your help, thanks!