Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Hey hey, me again, bouncing balls?

Jason

Awesome Bro

Hi,

So I'm stuck with something else which is REALLY annoying and I need help...

Basically, you play as, a ball shaped object, and instead of moving like a normal platformer, you know, stuck to the floor walking left and right, I want the ball to bounce.

I've tried making an animation of it bouncing, but this doesn't look right at all, I'd rather have a full functioning bouncing ball.

You might think "Just use the bounce drag and drop tool!", I've done this, but for example, if you're holding right, bounce off a platform and hit another, it carries on bouncing to the right, even when you hold it on left, it's like trying to fight against the wind, you can feel it TRYING to move to the left, but stuck in the course of moving to the right.

I'd like to know if there's a proper way of making a bouncing object like this, as it would really help me.

Another thing that would be incredible if I could get it to work, is if you hold the down button, it slams you to the floor (Obviously), but makes you bounce higher, as it would be required for specific areas.

Also (This is sounding huge, I'm sorry about it!), is there a way to make the bounces gradually get smaller and smaller? So the ball gradually loses height on its bounces unless the down button is pressed to increase it.

Thankyou!
 

Jason

Awesome Bro

Basically:

On collision with objFloor (That was the event)
Bounce precise.

I mean, the bouncing works, but I can't take control of the object once it's bouncing... it bounces and doesn't stop, if I try moving left, it just carries on bouncing in whatever direction it was going anyway.
 

OS

Sponsor

This is easier than it looks. Just set your vspeed equal to your jump height (a NEGATIVE number) in your collision event. I suggest making sure that the collision is underneath you, and then do a check for left|right to prevent moving through walls sideways.

Here is the code I just wrote up that works nearly perfectly (assuming there are no sideways walls):

Code:
 

Information about object: ball

 

Sprite: spr_ball

Solid: false

Visible: true

Depth: 0

Persistent: false

Parent: <no parent>

Mask: <same as sprite>

 

Create Event:

execute code:

 

gravity = 0.5;

 

 Step Event:

execute code:

 

UP = keyboard_check(vk_up);

DOWN = keyboard_check(vk_down);

LEFT = keyboard_check(vk_left);

RIGHT = keyboard_check(vk_right);

 

hspeed = (RIGHT - LEFT) * 5;

 

Collision Event with object solid:

execute code:

 

vspeed = -10;

 

My solid object is just named solid. It works great. Just do some work to make it so that if you wait too long before pressing down your jump speed decreases. I suggest using a variable staring at 10 and in the collision event say | vspeed = -jump_height | or something similar.

Hope this helps.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top