Exemple #1
0
        public override void DebugRender(Batcher batcher)
        {
            base.DebugRender(batcher);

            if (target != null)
            {
                batcher.DrawLineAngle(Transform.Position, Mathf.AngleBetweenVectors(this.Position, target.Position), 10, Color.Red);
            }

            batcher.DrawCircle(this.Position, 100f, Color.Red);
        }
Exemple #2
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;
        }