Ejemplo n.º 1
0
            private void Update()
            {
                IsGrounded = Physics.CheckSphere(_worldSpaceFeetPosition, _groundDetectionRadius, ~_ignoreLayers);
                GetInput();

                Vector3 normalizedGravity = GravityManager.CalculateGravityAtPosition(transform.position).normalized;

                ApplyRotation(normalizedGravity);
            }
Ejemplo n.º 2
0
            private void FixedUpdate()
            {
                bool rbIsAwake = !_rigidbody.IsSleeping();
                bool awake     = _rigidbody.velocity.magnitude > _sleepThreshold || (!_rbWasAwake && rbIsAwake);

                if (_useGravityInternal && awake)
                {
                    _rigidbody.AddForce(GravityManager.CalculateGravityAtPosition(transform.position), ForceMode.Acceleration);
                }

                _rbWasAwake = rbIsAwake;
            }
Ejemplo n.º 3
0
            private void Move()
            {
                Transform trans = transform;

                // this is the y component of the velocity in local space
                float localVerticalVelocity = (Quaternion.Inverse(trans.rotation) * _rigidbody.velocity).y;

                if (_jump)
                {
                    localVerticalVelocity += JumpForce;
                    _jump = false;
                }

                Vector3 input = _playerInput * Speed;
                Vector3 orientedInputVelocity = trans.rotation * new Vector3(input.x, localVerticalVelocity, input.y);

                Vector3 gravity = GravityManager.CalculateGravityAtPosition(trans.position);

                _rigidbody.velocity = orientedInputVelocity + gravity * Time.fixedDeltaTime;
            }