Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to make arrows not follow me?

Discussion in 'Scripting' started by matthewcooper, Jun 24, 2020.

  1. matthewcooper

    matthewcooper

    Joined:
    Apr 25, 2019
    Posts:
    40
    The arrow follows the player whereas I want the arrow to go to his last position, does anyone know how to do that? Also how would I add a weaponRange variable to this code?

    Code: https://pastebin.com/KAFjPh5J
     
  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    so you call

    Code (CSharp):
    1. transform.position = Vector3.MoveTowards(transform.position, target.transform.position, speed * Time.deltaTime);
    on your Update Loop, that makes the arrow follow your player / target nonstop ...

    To add a weaponRange you also need to have a "weapon" script i cant see here,
    to add it into your projectile you would need to define a float variable with the dedicated range and a function to trace your enemy as long as its closer then the weaponRange
     
  3. matthewcooper

    matthewcooper

    Joined:
    Apr 25, 2019
    Posts:
    40
    How do I change that so the arrow doesn't follow him?

    I think I can figure out the range on my own, I've got another weapon script.
     
  4. Mortalanimal

    Mortalanimal

    Joined:
    Jun 7, 2014
    Posts:
    566
    you have to save his last position first, save it on a list, and then make the arrow go to the last added position on that list.
     
  5. Mortalanimal

    Mortalanimal

    Joined:
    Jun 7, 2014
    Posts:
    566
    Nvm I think I miss understood you, the reason why it follows the player its because you have it on update, what you need to do, is make a reference of the target position at the point when the arrow is fired, and only use that reference. your using an updated position which changes over time.