- Home /
How can I make the NavMeshAgent travel only in straight lines?
Hi, I'm trying to make an AI in my game that will travel by jumping in straight lines toward the player. I got something working, but I can't seem to get obstacle avoidance working while making the AI travel only in straight lines. This is what I currently have.
Currently, the agent will only occasionally move toward the target, and will often just stop moving once it gets near an obstacle.
This seems like it would be super simple and require no nav mesh data. You simple raycast forward the distance to player, if no obstacles, take path, if obstacles, stop at obstacle and raycast from there toward player, and check angle, if it's block, and left is greater than right, take left path, then some time later have it raycast to player again. Does this make sense?
Or maybe I'm misunderstanding, and you just want them to move forward? In that case a simple rigidbody and a collider would work with
if (distanceFromPlayer > stopDistance)
body.velocity = transform.forward * speed * Tme.deltaTime.
Also please don't post pictures of code, no one is going to help you fix your code if they can't select it. Post your code as text in code format.
Your answer
Follow this Question
Related Questions
Navemeshagent and doors 1 Answer
How to build a custom shape NavMesh Area 1 Answer
Navmesh agent stuck on partial path 0 Answers
Runtime Navmesh not working on mobile build 0 Answers
Navmesh agent forward movement 1 Answer