Drawing a dynamic bullet trajectory

Get help using Construct 2

Post » Sat Aug 16, 2014 10:35 pm

Hi!
I'm making a defense based shooter and one thing I would really like adding is a predicted trajectory pathway cone, or something similar to it.
Here's the game in question: http://www.newgrounds.com/projects/games/732780/preview
Basically, the main projectile launcher increases the speed and accuracy at which it launches projectiles as it charged, so this trajectory would have to update in real time for it. The projectiles are also gravity based and aimable (go to the mouse position) and use the bullet behavior.

The closest thing I can think of is making fake markers with the bullet behavior leave the cannon (aiming at the mouse position) at increased DT, but I don't really think that would work very elegantly.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Sat Aug 16, 2014 11:35 pm

//Well, for speed I would go like this (for many instances, globals would become instance vars for obvious reasons):

global ChargeMeter

global ChargeMeterMax

global ChargeMeterPercentage

global BaseBulletSpeed

global MaxBulletSpeed

--------

Every tick set ChargeMeterPercentage to (ChargeMeter/ChargeMeterMax)

--------

Set bullet speed to lerp(BaseBulletSpeed, MaxBulletSpeed, ChargeMeterPercentage )

--------

//Accuracy would be a similar approach:

global Accuracy_MaxDeviation //In degrees

local AngleToTarget

Set AngleToTarget to angle(EnemyX/Y,Target_ProjectedX/Y) //Assuming you know how to do this

Set bullet angle to

lerp (
(AngleToTarget + ( (Accuracy_MaxDeviation * -1) * ChargeMeterPercentage ),
(AngleToTarget + ( (Accuracy_MaxDeviation) * ChargeMeterPercentage ),
random(0.0,1.0)
)

//Note: whoops, misread your post. Thought you were talking about enemies firing at the player. Left the above in case that might be helpful. The bullet speed equation would be unchanged; all you need to do to the angle equation would be to change 'Set AngleToTarget to...' the following:

Set AngleToTarget to angle(PlayerX/Y,MouseX/Y)

//If you want, you could do a projected mouseX/Y counting in gravity, etc, or maybe you want player to compensate manually? Anyway...
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,187

Post » Sun Aug 17, 2014 12:09 am

TiAm wrote://Note: whoops, misread your post. Thought you were talking about enemies firing at the player. Left the above in case that might be helpful. The bullet speed equation would be unchanged; all you need to do to the angle equation would be to change 'Set AngleToTarget to...' the following:

Set AngleToTarget to angle(PlayerX/Y,MouseX/Y)

//If you want, you could do a projected mouseX/Y counting in gravity, etc, or maybe you want player to compensate manually? Anyway...

Well, It's easy to draw a straight line from the gun to the mouse position. What I want to do is draw a line, or 2 lines that compensate for gravity, the accuracy of the projectile (A random +- angle of the gun, hence 2 lines for the min and max angle difference) and the velocity of the projectile, all of which change as the bullet charges longer.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Sun Aug 17, 2014 12:35 am

So I took a stab at it. It's kinda ugly right now but it works.
Image
Image

Basically I'm creating 2 bullets, one for the biggest possible angle of accuracy and one for the smallest. These two projectiles create a cone at which the bullet will travel. I increase their timescale to make them go faster than the bullet without changing the speed of the bullet (changing the speed would change the trajectory).
There's a bit of delay in the markers of course but it's better than nothing.
If anyone knows a better way please let me know.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Sun Aug 17, 2014 12:37 am

Pretty sure I came across something in the forums recently that did this, but for the life of me, can't remember what I was looking for when I came across it. I do remember r0j0hound was the one who solved it (no surprise there). I'll see if I can't find it again..

still got a couple of his capx links in my downloads folder
see if these help:

https://dl.dropboxusercontent.com/u/542 ... _phys.capx

https://dl.dropboxusercontent.com/u/542 ... annon.capx
B
86
S
43
G
71
Posts: 601
Reputation: 43,619

Post » Sun Aug 17, 2014 1:46 am

spacedoubt wrote:Pretty sure I came across something in the forums recently that did this, but for the life of me, can't remember what I was looking for when I came across it. I do remember r0j0hound was the one who solved it (no surprise there). I'll see if I can't find it again..

still got a couple of his capx links in my downloads folder
see if these help:

https://dl.dropboxusercontent.com/u/542 ... _phys.capx

https://dl.dropboxusercontent.com/u/542 ... annon.capx


This is really cool. Unfortunately I'm using the Bullet behavior, not Physics. I don't understand it well enough to convert it to Bullet.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Sun Aug 17, 2014 2:00 am

Yeah, me either.. heh..

Your solution doesn't look too shabby!
B
86
S
43
G
71
Posts: 601
Reputation: 43,619

Post » Sun Oct 26, 2014 4:57 am

hey @Sushin, I played your game.. it's great! really fun! seems like it just needs a few little tweaks and it's good to go! Really great job!
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Casimir, tarek2 and 11 guests