示例#1
0
        private void FollowTarget()
        {
            Vector3 xwingPosition = target.Position();

            float xwingVelocityScale   = Math.Max(0, Vector3.Dot(target.Velocity(), target.forward) / (target.forward.Length() * target.forward.Length())) / target.maxSpeed;
            float xwingDistance        = 45 + 20 * xwingVelocityScale;
            float cametaHeightDistance = 15 + 3 * xwingVelocityScale;

            if (Equals(position, Vector3.Zero))
            {
                position = xwingPosition - xwingDistance * target.forward + cametaHeightDistance * target.upDirection;
            }

            Vector3 newForward = Vector3.Normalize(xwingPosition - position);

            position = xwingPosition - xwingDistance * newForward;

            /*Vector3 mouseDirection = Vector3.Normalize(new Vector3(
             *  MathF.Cos(MathHelper.ToRadians(yaw)) * MathF.Cos(MathHelper.ToRadians(pitch)),
             *  MathF.Sin(MathHelper.ToRadians(pitch)),
             *  MathF.Sin(MathHelper.ToRadians(yaw)) * MathF.Cos(MathHelper.ToRadians(pitch))
             * ));*/

            forward = Vector3.Normalize(10 * forward + target.forward);
            right   = Vector3.Normalize(Vector3.Cross(forward, Vector3.Up));
            up      = Vector3.Normalize(up * 5 + Vector3.Cross(right, forward));
        }