Bouncing grenade in top down view using scaling

Get help using Construct 2

Post » Tue Dec 17, 2013 3:09 pm

In my top down game, I'm trying to create a realistic grenade which when thrown by the player does the following:

1) Gives the appearance of an arc by increasing the size/scale of the grenade sprite then decrease back to normal size to give the appearance of height (rather than using shadows)

2) Allow player to charge the grenade by holding down the mouse button, the greater the charge, the further the distance thrown and the greater the "fake" height

3) Bounce off any solids (regardless of the fake height)

4) Rotate the grenade sprite a random number of degrees while it is in the air on its origin imagepoint.

5) Bounce the grenade off the "floor" 3 times before coming to a stop (i.e. increase and decrease scale 3 times, in smaller increments each time).

6) Have grenade explode several seconds after being thrown and generate a short lived blast radius


In the capx below I have items 2, 3 and 6 implemented but not sure how to go about items 1, 4 and 5.

Any suggestions appreciated.

CAPX: http://www.sendspace.com/file/pzx3q5
B
5
S
1
Posts: 44
Reputation: 665

Post » Tue Dec 17, 2013 4:12 pm

Take a look at my game: http://balloonwarsgame.com. Playing the first level will give you some idea of how it works, specifically the water balloons. If you see anything you want to happen similar to the balloons for your grenades, let me know. I am actually working on changing the balloons arc to be shorter the closer you throw it, and bigger for the further away you throw it. Whatever you might want to know, I will tell you what I did to make it happen.
B
10
S
2
G
1
Posts: 64
Reputation: 1,032

Post » Tue Dec 17, 2013 6:34 pm

Concept wise it's similar to what I'm going for but your arc is from a first person perspective (large to small) whereas I'm looking for a straight top down arc (small - large - small). I'd be interested to know how you scale the balloons after throwing.

The other things I'm trying to do for regular grenades that I guess don't apply to water balloons are multiple bounces and rotation.

B
5
S
1
Posts: 44
Reputation: 665

Post » Wed Dec 18, 2013 11:08 pm


For the following to make sense, I created two global variables called GameWidth and GameHeight in my project.
At the start of a layout I set GameHeight = ViewportBottom(0) - ViewportTop(0), and GameWidth = ViewportRight(0) - ViewportLeft(0).

The following is assuming that the grenade sprite width is the same as its height

Give the grenade variables called MaxSize, MinSize, Peaked, and BouncesRemaining. (You can always change these to names that make more sense to you. All of these are Number, except for Peaked which is a Boolean)

When you spawn a grenade:
Set Grenade.MaxSize = GameHeight * 0.4 (play around with this value to get it the size you want)
Set Grenade.MinSize = GameHeight * 0.1 (again, whatever value works for you)

Now, I'm guessing that the size the grenade will start at will be a little bigger than when it hits the ground.
So, set Grenade.Height = Grenade.MinSize * 1.2
Set Grenade.Width = Grenade.Height

Make an event:
For Each Grenade                                      | Rotate Grenade Clockwise (or counter clockwise) 500 * dt
If Grenade.RemainingBounces > 0             (you can try other numbers instead of 500)
              
       | (subevent)
       |   If Peaked = False | Set Grenade.Height = Grenade.Height + ((Grenade.MaxSize - Grenade.Height) * dt * 300)
                             (300 might be too little or too big, so try different values)
                                 | Set Grenade.Width = Grenade.Height
                  |   (subevent)
                  |   If Grenade.Height > Grenade.MaxSize * 0.99 | Set Peaked = True (if you
                                                         find that the grenade spends too much
                                                         time at its peak, try another number
                                                         like 0.97 or 0.95 instead)


       | (subevent)
       |   Else                 | Set Grenade.Height = Grenade.Height - ((Grenade.MaxSize - Grenade.Height) * dt * 300)
                                | Set Grenade.Width = Grenade.Height
     
                  |   (subevent)
                  |   If Grenade.Height < Grenade.MinSize * 0.01 | Subtract 1 from Grenade.RemainingBounces
                                                                                                        | Set Grenade.Peaked to False
                                                                                                        | Set Grenade.MaxSize to Grenade.MaxSize * 0.5
                                                                                                         (play around with this number, such as 0.4, 0.3, etc.)

                             |   (subevent)
                             |   If Grenade.RemainingBounces < 1 | (The grenade is done bouncing, so you could either
                                                                                                     make it explode here, or it just stops)
                                   

Let me know how this works out for you
sgtwombatstudios2013-12-19 00:03:10
B
10
S
2
G
1
Posts: 64
Reputation: 1,032

Post » Thu Dec 19, 2013 8:55 am

I probably would have cheated and put an invisible side view grenade just off screen, bouncing on invisible ground. Then used it's Y distance from the invisible ground to set the scale of the actual grenade, the X along the invisible ground to determine the distance traveled.

edit: (in other words, the x would adjust the speed to match the scaling from the Y, so it would be a literal translation of the motion from the top view.) Paradox2013-12-19 08:57:35
B
226
S
60
G
33
Posts: 902
Reputation: 39,989

Post » Fri Dec 20, 2013 1:35 am

Yes, that's a great idea! I think that would be pretty easy, although if there were a lot of grenades, I don't know if the physics would slow down the game.
B
10
S
2
G
1
Posts: 64
Reputation: 1,032

Post » Fri Dec 20, 2013 2:33 am

I created one for an example a while back using the EaseTween behavior.

Not sure if it what's you are after, but you could then adjust the EaseTween settings depending on power. Like adjusting the Duration of the tween.

Press Z to throw, that's all it does :).
http://www.elf-games.com/games/grenade/

Link to capx, requires EaseTween behavior.
https://www.dropbox.com/s/vzucs5y7uon28vr/grenade-throw.capxArcadEd2013-12-20 02:35:44
B
100
S
32
G
11
Posts: 1,552
Reputation: 21,612

Post » Fri Dec 20, 2013 1:04 pm

Can't you use the behaviour/movement/sine to adjust the size of the grenade sprite over the length of the throw ? It should give you the correct arc and could save some maths ?

Edit

after a quick play

grenade test

capx

very rough but maybe ...?RamPackWobble2013-12-20 13:38:19
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 Dec 21, 2013 3:50 am

You may be able to do my solution with bullet behavior. Which is much faster than physics. It has gravity and bounce calculation too.
B
226
S
60
G
33
Posts: 902
Reputation: 39,989

Post » Wed Jan 01, 2014 5:48 pm


@sgtwombatstudios: your logic makes sense but am having trouble getting it working. See CAPX: http://www.sendspace.com/file/0ayn32

@RamPackWobble: your method gives a realistic arc, but I'd like to avoid creating separate sprites for the bounced grenade. Also I'd like to be able to modify the number of bounces without having extra code for each bounce, maybe using a function?

@Paradox, an example capx would be helpful to better understand what you're suggesting.

@ArcadEd: Which version of EaseTween are you using? Couldn't get your file open.
B
5
S
1
Posts: 44
Reputation: 665

Next

Return to How do I....?

Who is online

Users browsing this forum: alextro, tarek2, wenwen11212016, Yahoo [Bot] and 8 guests