Exemple #1
0
        public override void Update()
        {
            base.Update();

            if (target == null)
            {
                return;
            }

            // Get angle towards target
            var   targetAngle = Mathf.AngleBetweenVectors(this.Position, target.Position);
            float newAngle    = Mathf.ApproachAngleRadians(this.Rotation, targetAngle, turnSpeed);

            // Calculate a new heading based upon the new angle
            var newHeading = new Vector2(Mathf.Cos(newAngle), Mathf.Sin(newAngle));

            newHeading.Normalize();
            targetHeading = newHeading;

            // Rotate projectile to face target
            this.Rotation = newAngle;
        }