I have waypoint system for flying object (plane). To move from point to point I use:
body.velocity = (wayponts[current_point].position - transform.position).normalized * speed * Time.deltaTime;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation((wayponts[current_point].position - transform.position).normalized), Time.deltaTime * 2);
But I need to rotate this plane around his axes (like a fighter palne) by his angular (rotation) velocity. I have no idea how to do it.
I had a similar problem and this may or may not work for you as I’m not using physics or anything like that but maybe it will give a spark of inspiration. The problem for me was that each waypoint was re-writing the quaternion so trying to add a rotation to that kept making it freak out because it’s constantly being changed at the same time by the waypoints.
What I did was use an empty object that I called “driver” that carried the waypoint script and parented another empty game object I called “turner” to that, then parented my object (jet in your case) to turner.
The reason I did this is the driver object would change the direction of everything it was parent of but not affect the local transform of the child objects. I didn’t want to affect the jet directly in case I had other plans for it so I then had the parented turner object handle the local rotation. So the setup was like this:
Driver has waypoint script
>Turner has turn on key input script
>>jet just sits there being controlled by turner & driver
I’m basically removing the jet controls from the waypoint setup. I wanted to rotate 40 degrees instantly so my code for turning may not work for you but it may be a starting point. Obviously I still wanted to add to the current transforms so I add to the current rotation in update.
This may also be super clunky as I’m not a pro at this at all. But hey, it works for me.
void Update () {
if (Input.GetKey(KeyCode.RightArrow))
{
transform.localRotation = Quaternion.Euler(transform.localRotation.x, transform.localRotation.y, transform.localRotation.z + 40);
}
}
Hope this helps.