Object faces direction it is traveling?

EDIT: Ignore title

I have a plane and what I’m trying to achieve is have it tilt depending on the direction it wants to travel.
Except in this case, the direction comes first and the tilt should come second because I am telling it which direction it should travel by form of waypoints.

Depending on the game you might be better off always moving in the forward direction. To move in a different direction you rotate first… then move forward.

Well the thing is they move by following way points.

It just uses Move Towards function

Then couldn’t you just LookAt the waypoint marker? If it’s a GameObject, at least…

Okay time to whip out the horse.

I wanted to figure out a way to detect the direction of travel because I am doing something a bit more complicated than looking at the direction it’s headed.
I figured that is someone helped me with the above it would be easy to me to modify the script for my needs.
Yeah, I’m stupid.

I have a plane and what I’m trying to achieve is have it tilt depending on the direction it wants to travel.
Except in this case, the direction comes first and the tilt should come second (in terms of order of execution, you wouldn’t be able to tell the difference in game) because I am already telling it which direction it should travel (the way points). Does that make sense ?

Figured it out, sort of. Could look better but in the mean time it will have to do

private var enHealth:int=100;

private var prevX:float;

private var prevY:float;

private var dirY:float;

private var dirX:float;







function Start(){

	prevX=transform.position.x;

	prevY=transform.position.y;	

}





function Update(){



	if (quitMenu.pauseGame==false){



		Run();

	}





}





function Run(){



	if (enHealth<=10){

			

			Destroy (gameObject);

		

	}

	sideWays();





}





function sideWays(){



	if (transform.position.x<prevX){

		//left

		prevX=transform.position.x;

		dirX=3;



	}

	if (transform.position.x>prevX){

		//right

		prevX=transform.position.x;

		dirX=-3;

	}

	if (transform.position.z<prevY){

		//down

		prevY=transform.position.z;

		dirY=-3;

	}

	if (transform.position.z>prevY){

		//up

		prevY=transform.position.z;

		dirY=3;

	}



	

	rRotate(dirX,dirY);

	

}





function rRotate(dirX:float,dirY:float){





var tiltAroundX= dirY*5;

var tiltAroundZ = dirX*5;





var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ);

// Damper towards the target rotation

transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * 5.0);







}













function OnTriggerEnter(col: Collider)

{

//////////////////////////////////////////

	if (col.gameObject.tag == "myBullet")

	{

		enHealth-=10;

		

	}

 ////////////////////////////////////

}

If any of you are capable of improving it please do! The only thing that is missing is, tilting based on the speed