Exemple #1
0
    void FixedUpdate()
    {
        _isColliding = false; // reset isColliding

        // if we're moving gravity and not grounded
        if (gravEnabled && (GameController.gravTransitionState || !_grounded))
        {
            _rb.isKinematic = false; // we are now a dynamic rigidbody again
            PhysicsUtilities.ApplyGravity(_rb);
        }
        else
        {
            _rb.isKinematic = true;         // set rigidbody to kinematic to prevent physics when not in motion
            _rb.velocity    = Vector2.zero; // freeze the object
        }
        _grounded = isGrounded();
    }
    void FixedUpdate()
    {
        if (gravEnabled)
        {
            PhysicsUtilities.ApplyGravity(_rb);
        }
        else
        {
            _rb.velocity = Vector2.zero;
        }
        // only check for Grounded if we didn't override it with the idle check
        if (!_idleOverride)
        {
            grounded = isGrounded();
        }
        // Do the following to resolve any times colliders hit, and the raycasts fail
        // if we do so, override the normal grounded check
        Vector3 currentPos = transform.position;

        _idleCheck += Time.deltaTime;
        if ((!grounded || GameController.gravTransitionState) && _idleCheck >= .25f && currentPos == _lastPos)
        {
            //Debug.Log("In idle check");

            grounded = true;
            GameController.gravTransitionState = false;
            _idleCheck    = 0;
            _idleOverride = true;
        }
        _lastPos = currentPos;

        //Debug.Log("grounded: " + grounded);
        //Debug.Log("gravTrans: " + GameController.gravTransitionState);

        HandleInput();
    }