コード例 #1
0
        /// <summary>
        /// Physics
        /// </summary>
        void FixedUpdate()
        {
            EnforceAnchorPosition();

            UpdateVelocity();

            _isGrounded = sensors.leftSensor.grounded || sensors.rightSensor.grounded;

            _speed = _rigidbody.velocity.magnitude;

            _wagonAccel = _reverseAcceleration ? (_acceleration * (-1)) : _acceleration;

            _localVelocity = _transform.InverseTransformDirection(_rigidbody.velocity);

            TrainPhysics.UpdateWheels(wheelsScripts, _brake, _localVelocity.z);

            TrainPhysics.SpeedControl(_rigidbody, _isGrounded, _maxSpeedKph, Speed.Convert_MPS_To_KPH(_speed), _wagonAccel, _brake, _targetVelocity, out _targetVelocity, _currentSpeed, out _currentSpeed, _targetSpeed, out _targetSpeed);

            TrainAudio.PlaySFX(_sfx, Speed.Convert_MPS_To_KPH(_speed), _brake, false, _isGrounded);
        }
コード例 #2
0
        /// <summary>
        /// Train physics
        /// </summary>
        void FixedUpdate()
        {
            brake = automaticBrakes ? 1f - Mathf.Abs(acceleration) : brake;

            IsGrounded = sensors.leftSensor.grounded || sensors.rightSensor.grounded;
            _onRails   = sensors.leftSensor.onRails || sensors.rightSensor.onRails;
            _speed     = _rigidbody.velocity.magnitude;
            _speed_MPH = Speed.Convert_MPS_To_MPH(_speed);
            _speed_KPH = Speed.Convert_MPS_To_KPH(_speed);

            TrainAudio.PlaySFX(_sfx, _speed_KPH, brake, enginesOn, _isGrounded);

            _localVelocity = _transform.InverseTransformDirection(_rigidbody.velocity);

            if (!enginesOn)
            {
                acceleration = Mathf.MoveTowards(acceleration, 0f, GeneralSettings.DeaccelerationRate * Time.deltaTime);
                brake        = 1f;
            }

            TrainPhysics.UpdateWheels(wheelsScripts, brake, _localVelocity.z);

            TrainPhysics.SpeedControl(_rigidbody, _isGrounded, maxSpeedKph, _speed_KPH, acceleration, brake, _targetVelocity, out _targetVelocity, _currentSpeed, out _currentSpeed, _targetSpeed, out _targetSpeed);
        }