Beispiel #1
0
        private void ApplyFallColisionImpulse()
        {
            Vector2 velo = Velocity.Abs();

            Vector2 force = Vector2.Zero;

            force.X = Math.Sign(Velocity.X) * Math.Abs(velo.Y / 2.75f);
            ApplyLinearImpulse(force);
        }
Beispiel #2
0
        /// <summary>
        /// Calculates how far to move based on the current movement.
        /// </summary>
        /// <param name="percentOfSecond">How much time, percentage wise, has passed since the last Update.</param>
        public override void Move(double percentOfSecond)
        {
            double velocityLength;

            _acceleration = Forces / Mass;

            Position      += Velocity * percentOfSecond + _acceleration * percentOfSecond * percentOfSecond;
            Velocity      += _acceleration * percentOfSecond;
            velocityLength = Velocity.Length();

            // Stop moving if the "speed" is less than 10
            if (velocityLength < 10)
            {
                Velocity = Vector2.Zero;
            }
            else if (velocityLength > 3000) // Hack
            {
                Velocity = new Vector2(Rotation) * 600;
            }

            _acceleration = new Vector2();
            Forces        = new Vector2();

            Vector2 direction = new Vector2(Rotation),
                    dragForce = .5 * Velocity * Velocity.Abs() * DRAG_COEFFICIENT * DRAG_AREA * -1;

            if (Moving.Forward)
            {
                ApplyForce(direction * Power);
            }
            if (Moving.Backward)
            {
                ApplyForce(direction * Power * -1);
            }

            ApplyForce(dragForce);

            double rotationIncrementor = percentOfSecond * ROTATE_SPEED;

            if (Moving.RotatingLeft)
            {
                Rotation -= rotationIncrementor;
            }
            if (Moving.RotatingRight)
            {
                Rotation += rotationIncrementor;
            }
        }