Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Animation of NPC movement to a certain location

Discussion in 'Animation' started by PreeHooZheng, Mar 19, 2024.


Which solution is the correct solution for this problem?

  1. Use Bruteforce

    0 vote(s)
  2. Use NavMeshAgent

    1 vote(s)
  3. Another option (I'll post in the comments)

    0 vote(s)
  1. PreeHooZheng


    Oct 5, 2023
    Hello, community.

    Could you please advise me how to accomplish this task more correctly.

    In the scene, there is an NPC that should approach a selected target (in my image, I've labeled them with red circles) if that target is approached by a player.

    I see that there are two solutions.

    1- Bruteforce (bad solution):

    Make a set of animations (T0 -> T1, T0 -> T2, T0 -> T3, T0 -> T4, T1 -> T2, T1 -> T3, T1 -> T4 ... etc ). And run them depending on what position the NPC is currently in.

    2. use NavMeshAgent

    Can you tell me if I understand correctly that the only correct option is to use NavMeshAgent? Or is there a better solution

  2. jiraphatK


    Sep 29, 2018
    Yes. Use navmesh, play walk idle-forward-run base on velocity, rotate the character according to the velocity as well.
    PreeHooZheng likes this.
  3. launzone


    Dec 2, 2015
    I would say it is depending on what else you want to achieve in your project. Is this a one of thing, kind of like a cutscene where the animation should look very on point? Then I would create a custom animation that moves the character with their rootmotion to the specific spots (I guess what you call Bruteforce).
    Or is this something that you want to reuse for other situations with possible different target positions. Then definitely a movement system + separate animation system. Could be navmesh if there are obstacles to avoid or some uneven terrain. Otherwise you can just directly move the character to the positions with a Lerp for example.
    PreeHooZheng likes this.