Пример #1
0
        void Move(Path path)
        {
            Vector3D targetVelocity = path.Velocity;
            Vector3D myPos          = rc.GetPosition();

            Vector3D difference = path.Position - myPos;
            double   diffLen    = difference.Length();

            thrust.Velocity = difference + targetVelocity;
            thrust.Update();

            gyros.FaceVectors(path.Forward, path.Up);
            path.Update();
        }
Пример #2
0
        void Move()
        {
            gyros.FaceVectors(leaderMatrix.Forward, leaderMatrix.Up);

            Vector3D offset = storage.Offset;

            if (offset == Vector3D.Zero)
            {
                thrust.ApplyAccel(thrust.ControlVelocity(leaderVelocity));
                return;
            }

            // Apply translations to find the world position that this follower is supposed to be
            Vector3D targetPosition = Vector3D.Transform(offset, leaderMatrix);

            if (settings.calculateMissingTicks.Value)
            {
                int diff = Math.Min(Math.Abs(runtime - updated), settings.maxMissingScriptTicks.Value);
                if (diff > 0)
                {
                    double secPerTick = 1.0 / 60;
                    if (settings.tickSpeed.Value == UpdateFrequency.Update10)
                    {
                        secPerTick = 1.0 / 6;
                    }
                    else if (settings.tickSpeed.Value == UpdateFrequency.Update100)
                    {
                        secPerTick = 5.0 / 3;
                    }
                    double secPassed = diff * secPerTick;
                    targetPosition += leaderVelocity * secPassed;
                }
            }

            if (settings.enableCollisionAvoidence.Value)
            {
                CheckForCollistions(targetPosition);
                if (obstacleOffset.HasValue)
                {
                    thrust.ApplyAccel(thrust.ControlPosition(Vector3D.Transform(obstacleOffset.Value, leaderMatrix), leaderVelocity, settings.maxSpeed.Value));
                    return;
                }
            }

            thrust.ApplyAccel(thrust.ControlPosition(targetPosition, leaderVelocity, settings.maxSpeed.Value));
        }
Пример #3
0
        private void Move()
        {
            if (!lastEnemy.HasValue)
            {
                return;
            }

            rc.SetAutoPilotEnabled(false);

            Vector3D up = new Vector3D();

            if (useGravity)
            {
                up = Vector3D.Normalize(-rc.GetNaturalGravity());
            }

            Vector3D myPos = rc.GetPosition();

            if (detected)
            {
                // Target is in range, no prediction needed
                Vector3D enemyVel = lastEnemy.Value.Velocity;
                Vector3D enemyPos = lastEnemy.Value.Position;
                Echo(enemyPos.ToString());
                if (useRockets)
                {
                    enemyPos = GetRocketLead(enemyPos, enemyVel);
                }
                else
                {
                    enemyPos = GetLeadPosition(enemyPos, enemyVel);
                }
                Echo(myPos.ToString());
                Vector3D meToTarget = Vector3D.Normalize(enemyPos - myPos);
                gyros.FaceVectors(meToTarget, up);

                Fire(meToTarget);

                Vector3D velocity = enemyVel;
                if (fire)
                {
                    Vector3D target     = enemyPos + Orbit();
                    Vector3D difference = target - myPos;
                    double   diffLen    = difference.Length();
                    Vector3D stop       = thrust.StopDistance(1, enemyVel);
                    double   stopLen    = stop.Length();
                    if (!double.IsInfinity(stopLen))
                    {
                        if (stopLen > diffLen)
                        {
                            difference = Vector3D.Zero;
                        }
                        else
                        {
                            difference -= stop;
                        }
                    }
                    velocity += difference;
                }
                thrust.Velocity = velocity;
            }
            else
            {
                // Move towards predicted enemy position
                fire = false;
                double sec = Clock.GetSeconds(contactTime);
                if (sec > timeout)
                {
                    lastEnemy = null;
                    thrust.Reset();
                    gyros.Reset();
                    if (returnToOrigin)
                    {
                        ReturnOrigin();
                    }
                    return;
                }
                else
                {
                    Vector3D enemyVel   = lastEnemy.Value.Velocity;
                    Vector3D enemyPos   = lastEnemy.Value.Position + enemyVel * sec;
                    Vector3D meToTarget = Vector3D.Normalize(enemyPos - myPos);
                    gyros.FaceVectors(meToTarget, Vector3D.Zero);

                    Vector3D difference = enemyPos - rc.GetPosition();
                    double   diffLen    = difference.Length();
                    if (diffLen < turretRange)
                    {
                        return;
                    }

                    // Compensate for the velocity of the ship so the ship doesn't run into the target
                    Vector3D stop    = thrust.StopDistance(1, enemyVel);
                    double   stopLen = stop.Length();
                    if (!double.IsInfinity(stopLen))
                    {
                        if (stopLen > diffLen)
                        {
                            difference = Vector3D.Zero;
                        }
                        else
                        {
                            difference -= stop;
                        }
                    }

                    Vector3D velocity = enemyVel + difference;
                    if (!double.IsInfinity(maxSpeed))
                    {
                        double speed2 = velocity.LengthSquared();
                        if (speed2 > maxSpeed2)
                        {
                            velocity = (velocity / Math.Sqrt(speed2)) * maxSpeed;
                        }
                    }
                    thrust.Velocity = velocity;
                }
            }
            thrust.Update();
        }