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

Move to certain radius within target

Discussion in 'Scripting' started by agentalderson, Jun 16, 2018.

  1. agentalderson

    agentalderson

    Joined:
    Jun 7, 2018
    Posts:
    10
    Hi, I'm trying to think of a way to get my character to move to within a radius of 15 of the target before shooting. I set up a float that keeps track of Distance between the character and the target, but I'm wondering how to alter the movement vector so that the displacement is 15 away from the target. Any ideas on how I might achieve this?
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Your intention is clear but your scenario is vague. :) Is this a 2D or 3D scenario? Are you using a NavMesh or less constrained movement?

    If you are using a NavMesh, then you will want to set the character as the target for the Nav Agent. If not using a NavMesh, you could consider using MoveTowards.
     
  3. agentalderson

    agentalderson

    Joined:
    Jun 7, 2018
    Posts:
    10
    I managed to figure out a solution to it. I was using a 3D space, and I just ended up using a couple of variables to check the distance after certain actions have been performed. I would post my solution, but it's only really relevant because of the context of the script, so I don't think it will help anyone.