Beispiel #1
0
        private MovementData GetCurrentMovementData()
        {
            if (EngineManager != null)
            {
                return(EngineManager.CurrentMovementData);
            }

            if (MovementData != null)
            {
                return(MovementData);
            }

            return(MovementData.Zero());
        }
 public void Start()
 {
     rigidbody    = GetComponent <Rigidbody>();
     movementData = gameObject.GetComponent <MovementData>();
 }
Beispiel #3
0
        public void FixedUpdate()
        {
            // Throttle: y up/down x left/right z forward/backward
            // Local Velocity: z up/down. y forward/backwrads. x left/right
            LocalVelocity = transform.InverseTransformDirection(rigidbody.velocity);
            MovementData movementData = GetCurrentMovementData();

            if (IsControllable == false || rigidbody == null || rigidbody.isKinematic == true)
            {
                return;
            }

            // Forward
            if (throttle.z > MovementData.CONTROL_DEADZONE)
            {
                if (ApplyForceLocation == null)
                {
                    rigidbody.AddForce(throttle.z * movementData.ForwardAccelerationSpeed * transform.forward, ForceMode.Acceleration);
                }
                else
                {
                    rigidbody.AddForceAtPosition(throttle.z * movementData.ForwardAccelerationSpeed * transform.forward, ApplyForceLocation.position, ForceMode.Acceleration);
                }
            }

            // Backwards
            if (throttle.z < -MovementData.CONTROL_DEADZONE)
            {
                if (ApplyForceLocation == null)
                {
                    rigidbody.AddForce(throttle.z * movementData.BackwardsAccelerationSpeed * transform.forward, ForceMode.Acceleration);
                }
                else
                {
                    rigidbody.AddForceAtPosition(throttle.z * movementData.BackwardsAccelerationSpeed * transform.forward, ApplyForceLocation.position, ForceMode.Acceleration);
                }
            }

            /// Ascend Descend
            if (Mathf.Abs(throttle.y) > MovementData.CONTROL_DEADZONE)
            {
                rigidbody.AddForce(throttle.y * movementData.AscendDescendSpeed * transform.up, ForceMode.Acceleration);
            }

            // Rotation
            if (!isModifierDown)
            {
                rigidbody.AddTorque(transform.up * (throttle.x * movementData.RotationSpeed), ForceMode.Acceleration);
            }

            // Strafe
            if (isModifierDown)
            {
                rigidbody.AddForce(throttle.x * movementData.StrafeSpeed * transform.right, ForceMode.Acceleration);
            }

            if (EngineSound != null)
            {
                EngineSound.AccelerateInput(throttle.magnitude >= 1 ? movementData.RPMSpeedThrottleDown : 0f);
            }
        }