Search Unity

How can I check a simple trajectory?

Discussion in 'Scripting' started by Marscaleb, Sep 25, 2021.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,037
    I'm starting work on an enemy who is going to lob projectiles at the player, but they are going to travel in an arc.
    Is there a simple method to try to determine the viability of a curved path?

    Like, we've got all these raycast functions that let me check a direct line to see if anything would block a straight-line path. We've got options to test those paths with spheres and capsules. But do we have a method to do a quick raycast or raycast-like-thing over a curved path?

    I want to be able to perform a check if a lobbed projectile could feasibly hit a target.
    I could devise a look-up table that says if target is X distance then fire at Y angle, and maybe even one that adjusts for various heights. But I'd like to check the path of the projectile so I don't wind up with stupid exploits where you can stand right next to a barrier of some kind and all the shots miss. But I also want something that isn't too processor intensive because I could have dozens of these guys in the scene, and I could be checking for a firing solution repeatedly.
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
    i'd try raycast along the path (multiple raycasts along the segments, not necessarily full path resolution, if its really smooth curve..)
     
  3. alexeu

    alexeu

    Joined:
    Jan 24, 2016
    Posts:
    257
    and many tutos concerning trajectory prediction on YT
     
  4. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    Also look up Parabola Arc.
     
  5. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,037
    I took a look, but it was surprisingly unhelpful.
    All the tutorials were about drawing an arc in the scene so you could see a trajectory. And each tutorial I saw used a different method to do this, but none of them seemed like ones I could adapt to my needs.

    I need to find what values would work to hit a target, and then test if the required path is clear. It's practically the opposite direction from what these videos are showing. Any maybe there is one that I could adapt for my needs, but I haven't found it.

    But thanks for the suggestion.
     
  6. alexeu

    alexeu

    Joined:
    Jan 24, 2016
    Posts:
    257