I am trying to point the front of a plane towards a waypoint in 3d space, and at the same time tilting it.
The below simple code is making my head spin. As I need to modify rb.rotation in two different ways I am obviously only applying the tilt with the below code.
//Rotation around the x and y axis so the front points towards the waypoint:
Vector3 aimDir = (currentWayPoint - transform.position).normalized;
rb.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(aimDir), turnspeed * Time.deltaTime) ;
//tilt, turning to the left
if (Quaternion.LookRotation(aimDir).eulerAngles.magnitude - transform.rotation.eulerAngles.magnitude > 0)
{
rb.rotation = Quaternion.Euler (0.0f, 0.0f, 5.0f);
}
else //turning to the right
{
rb.rotation = Quaternion.Euler (0.0f, 0.0f, -5.0f);
}
As you see I am currently overwriting the rb.rotation in the if statements, so I need some additional functions there.
Quaternions is a strange black box to me, so how do I apply both of these rotations?