- Home /
Possible to edit the movement of NavMeshAgent ?
Hello!
I am fiddling with my first pathfinding behaviour. I am using a navmesh and the built in NavMeshAgent and it works great so far!
But I want the agent to take a wider, curved turn (because the agent-object is a vehicle) [Check the illustration below to see what I mean].
If I could edit the navmesh properties at some extend or even create my own navmesh agent, I could say that the agent can only go forward and Slerp the rotation towards the target.
Does anyone know of a editable NavmeshAgent template code??
Or have any other good tips on how to get the navmesh-agent to do a wider curved vehicle-like turn/rotation?
What I have tried:
A empty gameobject with the unity NavMeshAgent component that goes towards a destination target
A object with the vehicle model and a script saying it should only go forward and rotate towards the navmeshagent (this creates a nice and wide vehicle-like turn/rotation)
But the problem with this is that vehicle-object goes of the navmesh and collides with obstacles, because it takes a wider turn than the navmeshagent.
Illustration showing how the NavmeshAgent turns at the moment VS how I want it to turn:
Thanks for any kind of help!
Answer by UNZoOM · Mar 19, 2015 at 10:53 PM
This js should work.
Attach it to the nav mesh agent ( your car ) and it shall serve the purpose.
To make it smoother play with the nav Agents ( Angular speed value ).
targets is an array of Transforms where you can plugin the waypoints.
currentTarget can be your 1st way point ( targets[0] , or you can drag in the inspector )
navigation is your NavMeshAgent.
public var currentTarget : Transform;
public var targets : Transform[];
public var navigation : NavMeshAgent;
var incr:int;
function Start ()
{
navigation.destination = targets[i].position;
}
function Update ()
{
var dist = Vector3.Distance(targets[i].position,transform.position);
currentTarget = targets[i];
if (dist < 5){
if (i < targets.Length - 1)
{
i++; //change next target
incr++;
navigation.destination = targets[i].position;
}
}
}
But that only searches for the next waypoint, right?
I am afraid that does not solve my problem, as I know how to search for waypoints. Thanks for trying though :)
Answer by 10yaseen1 · Aug 29, 2015 at 02:47 PM
I am not sure if you still need a answer to this but how about using RotateTowards
method? It works rather smoothly for basic humanoid characters as far as I have noticed, might work with a car as well, although I don't think creating a car AI that way would do any good.