Drawing a dynamic bullet trajectory

0 favourites
  • 8 posts
From the Asset Store
You need this package if you want to program a Street Fighter or battle game.
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • //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...

  • //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.

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

    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.

  • 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

  • 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.

  • Yeah, me either.. heh..

    Your solution doesn't look too shabby!

  • 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!

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