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(); }
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(); }