Unity NavMesh path-finding with my own moment script.
I have kept my game fairly modular up to this point. Players and bots in my game use the same scripts for the most part. I also want to make the bot movement the same as the player movement. My player moves with the method call here that takes two floats for direction and a bool to jump.
player.Move(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), Input.GetButton("Jump"));
I would like my bot to be able to use that same Move method and navigate the scene avoiding obstacles. How can this be done? Thanks in advance.
Answer by BusinessPenguin · Oct 22, 2020 at 12:11 AM
Got it. My current solution is this
NavMeshPath path = new NavMeshPath();
navMeshAgent.CalculatePath(currentTarget.transform.position, path);
if(path.corners.Length != 0) desiredDir = (transform.position - path.corners[0]).normalized;
player.Move(desiredDir.x, desiredDir.y, false);
Your answer
Follow this Question
Related Questions
need help in obstacle avoidance math 2 Answers
C# Unity Move the player along a* found path 0 Answers
How can I setup a AI Bot to Pathfind around my small map? 0 Answers
Choose random point within an angular field of view 0 Answers
2D NPC Movement 0 Answers