How to make an npc/ai walk next to the player? (C#)
Hello, I'm trying to get an NPC to walk beside the character as shown here. Currently, the NPC will walk towards the player while the distance between it and the player is greater than 2m. The NPC will then rotate to face the same way as the player (as shown here)
The code for the dog is here (I tried pasting it into this post but it came out weird)
I've been trying to find tutorials on how to do it, but the ones that I'd found didn't make the NPC do what I wanted. If you have any pointers on what I should be doing or feedback on the code above, I would greatly appreciate it :D
Edit - 07/11/16 I haven't tried it yet but my theory for the solution would be to create an empty object, as a child of the character object, then offset it to the right/left side of the character. Instead of having the NPC make its way to the character it would instead go towards the empty object.
Answer by ResistanceGaming · Apr 10, 2017 at 06:58 AM
if you haven't figured this one out yet, have you tried doing something like:
transform.position.x = (target.transform.position.x + distance);
and just execute that once the follower has moved to the desired position or you could even change the lookat to that position once the npc is close enough and then once it reaches that position hold it there.
Your answer
![](https://koobas.hobune.stream/wayback/20220612100156im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Fixing enemy behavior state machine in Unity 0 Answers
Enemy AI script for 2D platformer 1 Answer
How do I make AI objects not walk on top of each other? 5 Answers
(SOLVED) Need help with Script that is supposed to get components of an AI and change them 1 Answer
HELP!! How to make my Mixamo Character sit on a CHAIR?? A* Pathfinding + Mixamo Animation 0 Answers