# [SOLVED] - Manipulated model eventually flies off screen!

I have a plane that can fly around over some terrain…

I can control the plane perfectly, and fly from visual and/or instruments…

HOWEVER…!

when I eventually change my planes orientation enough times, through course corrections etc, it freaks out and becomes over-sensitive to control inputs, and quicly flies off screen, twisting in chaos…

## I use the following code to change pitch(stick forward / back):

``````     orientation *= Matrix.CreateFromAxisAngle(orientation.Right, changeAmount.X);
``````

## and this to change roll(stick left / right):

orientation *= Matrix.CreateFromAxisAngle(orientation.Forward, changeAmount.Z) ;

-These are the only changes I make to orientation, so I’m pretty clueless right now…

Even if I botched my rotation code, why the model would eventually fly away, even wtihout movement code, is beyond me…

-I have noticed the plane gains speed when i freaks out as well… what the heck?

Is this not how you guys would set a planes rotation?

Any thoughts welcome, no idea is too small!

My guess is that `orientation.Right` and `orientation.Forward` are becoming non-normalized and thru the feedback loop of changing `orientation` with itself causes it to numerically explode.

I suggest trying this:

``````orientation *= Matrix.CreateFromAxisAngle(Vector3.Normalize(orientation.Right), changeAmount.X);
orientation *= Matrix.CreateFromAxisAngle(Vector3.Normalize(orientation.Forward), changeAmount.Z);
``````

You might also want to try combining your pitch and roll first then applying it to your orientation.

If you continuously add to a model’s rotation without resetting (as you are doing by multiplying a rotation matrix onto the existing orientation), the accumulation of floating point error will cause some odd behaviour, such as the model’s scale getting smaller. This is because the rotation in a matrix occupies the same cells that affect the model’s scale. Every floating point calculation has a small amount of error in it. By multiplying one matrix onto another, then multiplying another onto that, and another onto that, and another that, and so on, these floating point errors compound until they become significant enough to have a visible effect.

The way around this is to create the model’s transform matrix from a position, rotation and scale each frame. This means storing the position (Vector3), rotation (Vector3 or Quaternion) and scale (float or Vector3) separately, doing the updates on those (translating position, setting rotation), then create the matrix from those values. This way the only floating point error is the tiny amount from the matrix creation, and none from previous matrix operations.

[quote=“Tom, post:2, topic:2537”]
I suggest trying this:

orientation *= Matrix.CreateFromAxisAngle(Vector3.Normalize(orientation.Right), changeAmount.X);
orientation *= Matrix.CreateFromAxisAngle(Vector3.Normalize(orientation.Forward), changeAmount.Z);

THIS! thank you… Works longer than my patience for now, I will mark this as solved.

Is this what you mean?:

``````              if (my_rotation.Z > MathHelper.TwoPi)
{
my_rotation.Z -= MathHelper.TwoPi;
}
else if (my_rotation.Z < -MathHelper.TwoPi)
{
my_rotation.Z += MathHelper.TwoPi;
}
``````

If so, I only need to do this for properties I manipulate directly?