I got a method which is called by the Xna.Game.Update method with values for
Throttle (main thruster which shall make the spaceship move along its z axis)
Yaw (makes the spaceship strafe along its x axis)
Roll (makes the spaceship roll along its z axis)
Pitch (makes the spaceship roll along its x axis)
Lift (makes the spaceship move along its Y axis)
the ship has a mass of 100
gravity is -9.81 (ok i know, a spaceship on earth...)
if there is no lift, the spaceship shall "hover".
I feed it with values about 500 - 2500 * duration
duration = (gameTime.ElapsedGameTime.Milliseconds / 1000.0f)
But unfortunatly its not working very nice, it become uncontrolable very quick.
Is there anybody who maybe has a clue how to get the right values to control the spaceship like a pilot could do?
thx Grobi
Code: Select all
public void Update(float Throttle, float Yaw, float Roll, float Pitch, float Lift)
{
Vector3 direction = Vector3.Normalize(new Vector3(worldMatrix.M31, worldMatrix.M32, worldMatrix.M33));
Vector3 trust = (direction * -Throttle);
Vector3 yaw = worldMatrix.Left * Yaw;
Vector3 roll = worldMatrix.Up * Roll;
Vector3 pitch = worldMatrix.Up * Pitch;
Vector3 lift = worldMatrix.Up * (Lift);
Vector3 p = Vector3.Zero;
if (Yaw != 0)
{
p = Vector3.Transform(new Vector3(0, 0, boundingBox.Max.Z - boundingBox.Min.Z), Matrix.CreateFromQuaternion(body.orientationQuaternion));
p += body.centerOfMass;
body.applyImpulse(p, yaw);
}
if (Roll != 0)
{
p = Vector3.Transform(new Vector3(-(boundingBox.Max.X - boundingBox.Min.X), 0, 0), Matrix.CreateFromQuaternion(body.orientationQuaternion));
p += body.centerOfMass;
body.applyImpulse(p, roll);
}
if (Pitch != 0)
{
p = Vector3.Transform(new Vector3(0, 0, (boundingBox.Max.Z - boundingBox.Min.Z) / 2), Matrix.CreateFromQuaternion(body.orientationQuaternion));
p += body.centerOfMass;
body.applyImpulse(p, pitch);
}
if (Lift != 0)
{
p = body.centerOfMass;
body.applyImpulse(p, lift);
}
else
{
Vector3 slidingVelocity = -body.internalLinearVelocity;
slidingVelocity.X = 0;
slidingVelocity.Z = 0;
body.internalLinearVelocity += slidingVelocity;
}
p = Vector3.Transform(new Vector3(0, 0, boundingBox.Max.Z - boundingBox.Min.Z), Matrix.CreateFromQuaternion(body.orientationQuaternion));
p += body.centerOfMass;
body.applyImpulse(p, trust);
}