Quick question: Identify bullet bouncing

0 favourites
  • 5 posts
From the Asset Store
Bouncing ball
$9.99 USD
Template for a bouncing ball game, fully documented in comments and video
  • Quick question:

    Are there a way to identify when a bullet sprite have bounced and changed direction?

    <img src="smileys/smiley17.gif" border="0" align="middle" />

    Ok, I think it would be good to explain why I want this:

    Sometimes in my game (breakout style) the ball may start to bounce back and forth in exact same path for loooong time, so I have to break the game. I considered if I could figure out the bounce position and put the variable in array and then compare, after like 4-5 times of identical or similar values, I let it adjust the angle tiny bit. But how to implement it.. hmm.

  • I would just go for something like

    every 4 second

    ball.bullet.angle=ball.bullet.angle+random(-0.2,0.2)

    (play with time period and amounts)

    this would correct any stuck balls but not be noticeable during normal game play.

  • Hi Helena, Its a good question

    But I don't think just adding a random amount every few seconds is what you really need, I could be wrong..but doing that, it would make the Balls flight path unpredictable in a steadily incremental but consistently erratic manner..

    Which might be good for funny effects but doesn't simulate accuracy..

    I'm also pretty certain that the specific function you require isn't part of The Bullet behaviour Maybe you could suggest its Addition in the Forums...t would be a nice feature

    There is a manual work around though that might help and would give you highly 'precise' control over the flight path of the Rebounding Bullet...

    Firstly,

    To your "Ball" object add an Instance Variable called "Number of Rebounds" or similar & make it a "Number" Type Variable Initial Value 0

    Then make a new Event that reads

    Ball--> on Collision...Add 1 to Instance Variable "Number of Rebounds" or whatever you named it

    Then a new Event or sub event that reads...

    Ball-->Compare Instance Variable("Number of Rebounds") is Equal to (4 or 5)

    Actions--> Reset Instance Variable("Number of Rebounds")

        --> set Ball.Angle to (Ball.Angle) + 1 (more or less if you like)

        --> Bounce off Object(wall)

         

    That should be a workable solution for Precise control.

    Or the only other idea I can think of is to add a tiny angle of deflection to every rebound ......even a single degree would do it

    Assuming you are using the Bullet Behaviour,

    There is a "Bounce off" action in the list of events after collision

    I presume this is there to enable custom actions in addition to the standard Bullet Behavior

    The Events you would need would be something like

    -->Ball--->On collision with(walls?)

              --> Bounce off Object(wall)

              --> set Ball.Angle to (Ball.Angle) + 1

    This would make the ball slightly adjust its flight path ..

    barely noticeable most of the time but would theoretically prevent it from staying in a locked pattern

    You would need to make certain that The Bullet Behaviour "Set Angle" Property in the Property Inspector Tab is Set to "Yes"

    Otherwise the Bullets Flight path will not match its Sprite Angle

    Timed events may add unnecessary erratic additions to the flight path

    of the ball...

    But the best way is to test all the methods and see what works best for your game

    The most accurate way is to use the On collision Condition events

    Another Idea would be to add a tiny amount of Gravity to the Ball object in the Property Inspector Tab...This would always exert a slight natural downwards or upwards force on the Ball..

    The Bullet Behaviour has built in Gravity Physics

    Hope that helps

  • another idea - assuming you have only vertical and horizontal blocks - just check see if ball angle is 0,90,180 or 270 and if so alter it a bit ?

    (but I would still only run this check "once in a while" not every frame)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • RamPackWobble and mystazsea

    Thank you two for replying.

    I went with Mystazseas solution, more or less.

    I decided to do it manually, and remove all solid behavior and made the bounce event based so I could add variable. I decide to change angle +1 every 6th time.

    For people reading, do not use .Angle, it is not same thing, it is .Bullet.AngleOfMotion the Angle is for the sprite itself, not motion. This confused me first then ooh.

    Also pay attention to how you arrange event blocks. I accidentally moved the whole group under some obscure event and did not get it why it never worked in the actual game but working nicely in the test capx. ;)

    Thanks again guys!

    Now I wish I had extra monitor to see the debug window better! I clutter my game with texts showing how things go. ;)

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