I’m trying to make a ball not only bounce, but bounce across the screen and hurt the player. Think boss fights from a classic Donkey Kong Country game where some bosses throw (or shoot) projectiles at you and you have to avoid them.
What is the expected result
I want the ball to bounce from the enemy on screen and bounce to the player. If it touches the player, they get hurt, but the player can jump over it and be fine.
What is the actual result
I looked up stuff about tweens, but honestly I’m still a bit confused on how to make the ball actually go up and down. I’m not really good with X and Y related things. And I tried the bounce behavior, but still not getting the desired results.
The bounce extension is more designed for an object colliding with another and the trajectory it takes after the collision. It’s not for a bouncing a ball.
To bounce with tweens, check out easings.net, which illustrates how the different easings behave.
My solution works for a flat surface. If there are differing height surfaces to bounce off, it won’t work.
To get it to bounce on the ground, change the value of the drop tween to floor.Y() - ball.Width()/2. This will allow for the ball radius and make it appear like the ball is hitting the floor.
However, it probably won’t work if there are multiple floor objects in the scene.
That suggest there’s a typo in your events. Can you screen shot them?
How far in the air? Like about 1/2 the ball’s height? If that’s the case, check that the ball sprite origin is at the centre of the object.
If it’s more, then change the 220 to Platform_Ground.Y() - SmallBlueBall.Height()/2, and also check that the ball sprite origin is at the centre of the object.
Okay, so good news is that it’s bouncing off the ground now, but it’s still bouncing high.
And to answer your question about how high it bounces in the air, in the picture I shared, it bounces just about where the top white part from the game area is located.
Sorry in advance, but I saw that I made a typo in one of my past comments.
“I was hoping for the ball to bounce on the ground, but it goes off screen on the right and disappears.”
I meant to say that I WANT the ball to go off-screen. Then afterwards, the enemy throws another ball at the player and the process repeats, until the scene timer ends.
Edit: I remembered about the “destroy the object when tween finishes” option.
My bad.
Thank you for the help. This is working pretty well.
I was just using a ball to get some ideas on how I want enemies to shoot or throw projectiles at you in my game and what I had to do to make that happen in the engine.