Search Unity

Onscreen projectile lead indicator for flying character

Discussion in 'Physics' started by theishiopian, Jan 15, 2021.

  1. theishiopian

    theishiopian

    Joined:
    Oct 23, 2015
    Posts:
    16
    I'm making a 6DOF 3rd person shooter. I want to have an onscreen indicator showing where the bullets will be onscreen at a certain time in flight. The projectiles travel at a constant speed with no external forces acting on them.

    All the answers I've found so far for "leading projectiles" have been for predicting which way to point your gun to hit a moving target. What I want to do is the opposite, predict where the bullets will go from a moving gun, and put a circle around the position predicted for a certain amount of travel time. This way, a player can lead their shots by tracking that circle onto a target, provided the player is at the appropriate distance. The player can rotate around all three axes, and move in all three as well, both of which need to be taken into account.

    Can anyone provide a solution?
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    Could you visually show what kind of indicator you're talking about? I'm just confused about why/how this makes sense if you mention that the projectiles are constant speed with no external forces acting on them. In that case, predicting where the bullet will go just means looking straight forward...
     
  3. theishiopian

    theishiopian

    Joined:
    Oct 23, 2015
    Posts:
    16
    I've found a workaround for now, but its not pretty. I'm using a particle system with similar ballistic properties to the projectiles, emitting a constant stream of particles, then checking lifetimes to get the last particle and setting the reticle to the corresponding screen position.

    I'd still be interested in a better solution, but this works well enough for now.

    Here's a video showing what I mean:
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    Ah, thanks for the video. I see what you're doing now, and I see how it could be useful. However, my first concern is that it won't actually be useful in practice unless the enemies are at a constant distance from you, which is unlikely since you can flow all around.

    When I say it might not be useful, I mean the following: That small circle, showing where the furthest bullet reached, could be useful for showing where your bullets will hit a moving target. You'd expect the player to try to get the enemy to fit inside the small circle. Or at least, that's the impression is gives. But that only if that moving target is the same distance from you as the max distance of the particle. If the target isn't the same distance as the max distance of the particle, then the projectile will reach the enemy's position too soon/late to hit it. So I guess before you invest more in this system, I'd recommend see if it actually helps you hit targets that are at various distances from you. My feeling is that this system will give you misleading results, where trusting the small circle as an indicator will mostly cause you to miss your shots.

    But maybe it would all work fine if you adjusted the max distance based on the distance to the target nearest the center of the screen? That way the small circles would always be rangefinding against an actual enemy?

    Anyway, as for a better approach to determining the position of the circles, I agree the particle system approach is a bit weird. I might just keep a queue of vector3 directions, which represent the direction the ship was facing 1 or 2 seconds prior. Maybe add to the queue every 1/10 seconds. Any time you add one, you remove the oldest one, then determine where a particle would be if it had travelled in that direction for 1 or 2 seconds, then put your circle there.
     
  5. theishiopian

    theishiopian

    Joined:
    Oct 23, 2015
    Posts:
    16
    That's an interesting solution, if I have time I'll look into implementing it. And I 100% agree that the circles are not useful if the distance to the target is highly variable. That's why I'm writing the AI to attempt to maintain a max distance from the player. The goal is that the distance will usually be somewhere between the effective distance of the circles.
     
    dgoyette likes this.