Keep Character facing forward in AIPath script

I’m using a standard character controller for movement, but I notice that in the AIPath script, the movement is controlled with this code:

controller.SimpleMove (dir);

This causes the character to skate sideways toward the target. I’d like the character movement to always be in the forward direction and then turn toward the target. Is there a simple way to do this?

By the way, I’m using a character controller because I’m using a kinematic rigidbody and animating physics. I’d rather use an RVO controller, but I don’t have too many AI characters so I’m hoping performance will be ok.

As always, thanks for the help.

`	var forward : Vector3 = mTransform.TransformDirection(Vector3.forward);
	controller.SimpleMove (forward * speed * Time.deltaTime);
	
	lookRotation  = Quaternion.LookRotation (path.vectorPath[currentWaypoint] - mTransform.position);
		
	mTransform.rotation = Quaternion.Slerp(mTransform.rotation, Quaternion.Euler (Vector3 (MyRot.x, lookRotation.eulerAngles.y, MyRot.z)), Time.deltaTime * rotateSpeed);	`

Might be jerky at times, but try playing around wiht the values to fit your setup

Thanks so much Linus. I’ll give it a try and get back to you.

I missed some part of the code. Here is the full Update function. If nodes are close together it can be a bit twitchy, but adjusting rotation speed and using modifiers helps on that.
I used this for moving a truck on roads using a point graph, and it stayed in its line.

`
var mTransform : Transform;

function Start(){
.......
mTransform = transform;
.....
}


function Update(){
	
	if(path == null){
	 return;
	}
	
	//Debug.Log(''+ currentWaypoint+' >= '+path.vectorPath.Count );
	if(currentWaypoint == path.vectorPath.Count){

		DestiantionReached();
		path = null;

		return;
	}
	
	var MyRot : Vector3 = transform.rotation.eulerAngles; 
	var lookRotation : Quaternion;
		
	var forward : Vector3 = mTransform.TransformDirection(Vector3.forward);
	controller.SimpleMove (forward * speed * Time.deltaTime);
	
	lookRotation  = Quaternion.LookRotation (path.vectorPath[currentWaypoint] - mTransform.position);
		
	mTransform.rotation = Quaternion.Slerp(mTransform.rotation, Quaternion.Euler (Vector3 (MyRot.x, lookRotation.eulerAngles.y, MyRot.z)), Time.deltaTime * rotateSpeed);	
	
	
	if ( (mTransform.position-path.vectorPath[currentWaypoint]).sqrMagnitude < nextWaypointDistance*nextWaypointDistance) {
		currentWaypoint++;
		return;
	} 

}`