Esempio n. 1
0
        private void TurnTowards(float seconds, Vector2 target)
        {
            float targetAngle    = this.GetClosestPointAtAngleInRange(target);
            float currentAngle   = Vector2Utils.MinimizeMagnitude(this.TurretDirectionRelativeToSelf);
            float maxAngleChange = seconds * this.AngularSpeed;

            if (this.Range >= Math.PI)
            {
                this.TurretDirectionRelativeToSelf = PhysicsUtils.AngularMoveTowardBounded(currentAngle, targetAngle, maxAngleChange);
            }
            else
            {
                if (Math.Abs(currentAngle - targetAngle) <= maxAngleChange)
                {
                    this.TurretDirectionRelativeToSelf = targetAngle;
                }
                else if (targetAngle < currentAngle)
                {
                    this.TurretDirectionRelativeToSelf = currentAngle - maxAngleChange;
                }
                else
                {
                    this.TurretDirectionRelativeToSelf = currentAngle + maxAngleChange;
                }
            }
        }
Esempio n. 2
0
        public override void SubclassUpdate(float seconds)
        {
            base.SubclassUpdate(seconds);

            this.Position = this.Position + (this.Velocity * seconds);

            if (this.TargetAngle <= Math.PI * 2 && this.TargetAngle >= 0)
            {
                float changeInAngle = (float)(seconds * this.AngularSpeed);
                this.Direction = PhysicsUtils.AngularMoveTowardBounded(this.Direction, this.TargetAngle, changeInAngle);
            }
            else
            {
                this.Direction = this.Direction + (float)(seconds * this.AngularSpeed);
            }
        }