public void StabelizeUpwards(Vector3D groundUpVector)
            {
                Vector3D velocity = rc.GetShipVelocities().LinearVelocity;

                velocity.Normalize();

                Vector3D upVector      = groundUpVector;
                Vector3D forwardVector = VectorUtils.ProjectOnPlanePerpendiculair(rc.WorldMatrix.Left, rc.WorldMatrix.Forward, velocity);

                if (groundUpVector == Vector3D.Zero)
                {
                    upVector = Vector3D.Normalize(-rc.GetNaturalGravity());
                }

                upVector += pitchUpBias * rc.WorldMatrix.Backward;

                var refLeft    = rc.WorldMatrix.Left;
                var refUp      = rc.WorldMatrix.Backward;
                var refForward = rc.WorldMatrix.Up;

                double dotUp      = 1 - Vector3D.Dot(upVector, refForward);
                double multiplier = MyMath.Clamp((float)(dotUp * 2 * dotUp), 1, 10);

                MatrixD rotationMatrix = MatrixD.CreateFromDir(refForward, refUp);

                Vector3D moveindicatorUP = VectorUtils.Project(VectorUtils.TransformDirLocalToWorld(rc.WorldMatrix, rc.MoveIndicator), rc.WorldMatrix.Right);

                forwardVector += moveindicatorUP * userInputMultiplier;

                GyroUtils.PointInDirection(gyros, rotationMatrix, upVector, -forwardVector, multiplier * upwardStabelizationMultiplier);
            }
            public void Main()
            {
                if (accelerateTarget == null || accelerateTarget == Vector3D.Zero || accelerateTarget == Vector3D.PositiveInfinity || PID_Controller == null || !accelerateTarget.IsValid())
                {
                    return;
                }

                Vector3D accelerateTargetNormalized = accelerateTarget;
                double   accelerateTargetLength     = accelerateTargetNormalized.Normalize();
                double   error      = Vector3D.Dot(control.WorldMatrix.Forward, accelerateTarget) + accelerateTargetLength;
                double   multiplier = Math.Abs(PID_Controller.NextValue(error, 0.016));

                if (accelerateTargetLength < negligible)
                {
                    accelerateTargetNormalized = Vector3D.Normalize(control.GetShipVelocities().LinearVelocity);
                }

                GyroUtils.PointInDirection(gyros, control, accelerateTargetNormalized, multiplier);
                //ThrustUtils.SetThrustBasedDot(thrusters, accelerateTargetNormalized, multiplier);
                autopilotModule.ThrustToVelocity(control.GetShipVelocities().LinearVelocity + accelerateTarget);


                if (accelerateInDirection && control.GetShipSpeed() >= (speedLimit - 0.01))
                {
                    accelerateTarget = Vector3D.Zero;
                    BoostForward(0);
                    accelerateInDirection = false;
                }
            }
            public void Update()
            {
                if (!_targetUpdated)
                {
                    _target = InterpolateTarget();
                }

                Vector3D aimVector = Navigate(_target);

                GyroUtils.PointInDirection(_gyros, _gyros[0].WorldMatrix, aimVector);
                aimVector.Normalize();
                ThrustUtils.SetThrustBasedDot(_thrusters, aimVector);

                UpdatePayload();
            }
Exemple #4
0
 private void Rotate()
 {
     GyroUtils.PointInDirection(gyros, cockpit, target, 5);
 }
 public void AimMissile(Vector3D targetDir)
 {
     GyroUtils.PointInDirection(gyros, control, targetDir, 1, true);
 }