Bouncing ball inside a box

0 favourites
  • 7 posts
From the Asset Store
Enjoy the powerful simulation with accurate ball physics, build with realistic ball spinning animations
  • Hi

    I made a ball with the bullet behavior and I enabled "bounce off solids".

    The ball is moving diagonally (at 45, 135, 225, 315 angles) inside a box of 4 solid walls, and I made it switch the direction horizontally when the mouse is clicked using the "Is between angles" condition.

    Now the ball is bouncing off of the walls as intended, however if it hits one of the corners it will bounce in a random direction which is not what I want.

    How can I prevent this from happening?

    Capx: https://drive.google.com/open?id=1cPOsN5L0lYTlrwc1LTH7jrsHrnsCyySm

  • I made some changes:

    dropbox.com/s/f5r5tcmm04pna27/BounceBall2.capx

    Bullet angle is unreliable, so I added BallAngle instance variable and changing it with events.

    Bullet angle of motion is set to BallAngle on every tick. "Bounce off solids" is now disabled.

  • I made some changes:

    https://www.dropbox.com/s/f5r5tcmm04pna27/BounceBall2.capx?dl=0

    Bullet angle is unreliable, so I added BallAngle instance variable and changing it with events.

    Bullet angle of motion is set to BallAngle on every tick. "Bounce off solids" is now disabled.

    Thank you so much for your help, it's working perfectly now.

    However if I clicked the mouse at the same time the ball hits one of the vertical walls the ball would go through that wall or it would bounce back to the same way it came from.

    Do you think you can fix this?

  • You can add additional conditions to "On mouse click" event to ignore clicks when the ball is too close to the walls. One way of doing this is with inverted "overlapping at offset" event.

  • You can add additional conditions to "On mouse click" event to ignore clicks when the ball is too close to the walls. One way of doing this is with inverted "overlapping at offset" event.

    I just tried that but the game wasn't going really smooth, I don't think I made it right.

    Would you please show me the right way to do it?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • On mouse click
    Ball NOT overlapping Wall at offset X:-20, Y:-20
    Ball NOT overlapping Wall at offset X:20, Y:20
     (all the sub-events here)
    

    Clicks will be ignored if ball is within 20 px of the wall on either side.

  • > On mouse click
    Ball NOT overlapping Wall at offset X:-20, Y:-20
    Ball NOT overlapping Wall at offset X:20, Y:20
    (all the sub-events here)
    

    Clicks will be ignored if ball is within 20 px of the wall on either side.

    Perfect, thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)