NPC Flight Tilt

Hello:

I am trying to get an AI airplane to tilt as it turns. I adapted my player code like so:

var look = target.transform.position - transform.position;
var lookRotation = Quaternion.LookRotation(look);
var dir : Vector3 = lookRotation.eulerAngles;

euler.y += dir.x * rotateRate;
euler.z = Mathf.Lerp(euler.z, -dir.x * 50, 0.2);
euler.x = Mathf.Lerp(euler.x, dir.y * 50, 0.2);

var rot : Quaternion = Quaternion.Euler(euler);
transform.rotation = Quaternion.Lerp (transform.rotation, rot, 0.25);

Yet when I run the code the airplane gives me a bunch of weird jiggling, unlike my player character. Any suggestions?

I’m not sure what you’re doing with the Euler angles there, but it seems unlikely that it would produce the desired results.

Is the simulation basically 2-d? That is, do the game objects always move in the same plane? Or is it a fully 3-d environment?

It’s 3D.

Just to be clear, when you say it’s 3-d, do you mean the AI actually operates in 3-d?

Clearly, the simulation is 3-d because Unity is a 3-d engine. However, you can have a 3-d game (in terms of visuals, etc.) while having AI that essentially functions in a 2-d environment. That’s what I’m asking - is the AI essentially 2-d, or is it fully 3-d? (Maybe your answer will still be the same - just making sure.)

The AI should move up, down, forwards, backwards, left, and right, yes.

In that case you definitely don’t want to be working with Euler angles for this.

As for how to get the plane to orient itself realistically as it turns, I couldn’t really say without doing some experimenting myself. (Since it’s a fully 3-d simulation, it seems what you’re probably looking for is a realistic-ish simulation of flight dynamics rather than just an ad hoc ‘rolling’ effect.)