Quick question: Identify bullet bouncing

Get help using Construct 2

Post » Sat Jan 11, 2014 6:15 pm

Quick question:

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




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.helena2014-01-11 19:51:33
B
58
S
18
G
13
Posts: 447
Reputation: 10,735

Post » Sat Jan 11, 2014 11:19 pm

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.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Sat Jan 11, 2014 11:20 pm

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




mystazsea2014-01-11 23:34:49
When in doubt..or you are lost in a Zombie apocalypse or someone is giving you a hard time..Remember one thing..... Read the Construct 2 Manual..it will save your life.:)
B
35
S
13
G
8
Posts: 318
Reputation: 7,685

Post » Sat Jan 11, 2014 11:26 pm

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)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Sun Jan 12, 2014 12:56 am

@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. ;)helena2014-01-12 00:58:28
B
58
S
18
G
13
Posts: 447
Reputation: 10,735


Return to How do I....?

Who is online

Users browsing this forum: FlyingRam, Google [Bot] and 8 guests