Exemplo n.º 1
0
    void FixedUpdate()
    {
        //Run initial mover ground check;
        mover.CheckForGround();

        //Check whether the character is grounded;
        isGrounded = mover.IsGrounded();

        //Handle timeout (stop controller if it is stuck);
        HandleTimeOut();

        Vector3 _velocity = Vector3.zero;

        //Calculate the final velocity for this frame;
        _velocity            = CalculateMovementVelocity();
        lastMovementVelocity = _velocity;

        //Calculate and apply gravity;
        HandleGravity();
        _velocity += tr.up * currentVerticalSpeed;

        //If the character is grounded, extend ground detection sensor range;
        mover.SetExtendSensorRange(isGrounded);
        //Set mover velocity;
        mover.SetVelocity(_velocity);

        //Save velocity for later;
        lastVelocity = _velocity;
    }
    //FixedUpdate;
    void FixedUpdate()
    {
        //Check if mover is grounded;
        mover.CheckForGround();

        //Determine controller state;
        HandleState();

        //Apply friction and gravity to 'momentum';
        HandleMomentum();

        //Check if the player has initiated a jump;
        HandleJumping();

        //Calculate movement velocity;
        Vector3 _velocity = CalculateMovementVelocity();

        //Add current momentum to velocity;
        _velocity += momentum;

        //If player is grounded or sliding on a slope, extend mover's sensor range;
        //This enables the player to walk up/down stairs and slopes without losing ground contact;
        mover.SetExtendSensorRange(IsGrounded());

        //Set mover velocity;
        mover.SetVelocity(_velocity);

        //Store velocity for next frame;
        savedVelocity         = _velocity;
        savedMovementVelocity = _velocity - momentum;

        //Reset jump key booleans;
        jumpKeyWasLetGo   = false;
        jumpKeyWasPressed = false;
    }
Exemplo n.º 3
0
    void FixedUpdate()
    {
        if (wasInstantiated && photonView.IsMine)
        {
            //Check if mover is grounded;
            mover.CheckForGround();

            //Determine controller state;
            currentControllerState = DetermineControllerState();
            UpdateAnimation();

            //Apply friction and gravity to 'momentum';
            HandleMomentum();

            //Check if the player has initiated a jump;
            HandleJumping();

            //Calculate movement velocity;
            Vector3 _velocity = CalculateMovementVelocity();

            //If local momentum is used, transform momentum into world space first;
            Vector3 _worldMomentum = momentum;
            if (useLocalMomentum)
            {
                _worldMomentum = transform.localToWorldMatrix * momentum;
            }

            //Add current momentum to velocity;
            _velocity += _worldMomentum;

            //If player is grounded or sliding on a slope, extend mover's sensor range;
            //This enables the player to walk up/down stairs and slopes without losing ground contact;
            mover.SetExtendSensorRange(IsGrounded());

            //Set mover velocity;
            mover.SetVelocity(_velocity);

            //Store velocity for next frame;
            savedVelocity         = _velocity;
            savedMovementVelocity = _velocity - _worldMomentum;

            //Reset jump key booleans;
            jumpKeyWasLetGo   = false;
            jumpKeyWasPressed = false;

            //Reset ceiling detector, if one was attached to this gameobject;
            if (ceilingDetector != null)
            {
                ceilingDetector.ResetFlags();
            }
        }
    }
Exemplo n.º 4
0
    public void FixedUpdateController()
    {
        //Run initial mover ground check;
        mover.CheckForGround();

        //If character was not grounded int the last frame and is now grounded, call 'OnGroundContactRegained' function;
        if (isGrounded == false && mover.IsGrounded() == true)
        {
            OnGroundContactRegained(lastVelocity);
        }

        //Check whether the character is grounded and store result;
        isGrounded = mover.IsGrounded();

        Vector3 _velocity = Vector3.zero;

        //Add player movement to velocity;
        _velocity += CalculateMovementDirection() * movementSpeed;

        //Handle gravity;
        if (!isGrounded)
        {
            currentVerticalSpeed -= gravity * Time.deltaTime;
        }
        else
        {
            if (currentVerticalSpeed <= 0f)
            {
                currentVerticalSpeed = 0f;
            }
        }

        //Handle jumping;
        if ((characterInput != null) && isGrounded && characterInput.IsJumpKeyPressed())
        {
            OnJumpStart();
            currentVerticalSpeed = jumpSpeed;
            isGrounded           = false;
        }

        //Add vertical velocity;
        _velocity += tr.up * currentVerticalSpeed;

        //Save current velocity for next frame;
        lastVelocity = _velocity;

        mover.SetExtendSensorRange(isGrounded);
        mover.SetVelocity(_velocity);
    }
Exemplo n.º 5
0
    private void StartGrapple()
    {
        _lineRenderer.enabled     = true;
        _walkerController.enabled = false;

        _gravitySystem.GravityScale = Constants.GRAPPLING_GRAVITY_SCALE;

        _mover.CheckForGround();

        if (_mover.IsGrounded())
        {
            _rigidbody.AddForce(Vector3.up * _intialYLaunchForce);
        }

        InitializeSpringJoint();
        DrawLine();
    }
        private void FixedUpdate()
        {
            var deltaPlayerLocalPosition = Camera.main.transform.localPosition - savedPlayerLocalPosition;

            deltaPlayerLocalPosition.y = 0f;

            moverRigidbody.MovePosition(moverRigidbody.transform.position + (Quaternion.Euler(0f, PlayerManager.Instance.transform.eulerAngles.y, 0f) *
                                                                             new Vector3(deltaPlayerLocalPosition.x, 0f, deltaPlayerLocalPosition.z)));

            headCollider.transform.position = DesiredHeadPosition;

            ResizeMover();

            mover.CheckForGround();

            HandleState();

            HandleMomentum();

            HandleJumping();

            var velocity = CalculateMovementVelocity();

            velocity += momentum;

            mover.SetExtendSensorRange(IsGrounded);

            mover.SetVelocity(velocity);

            if (velocity.x != 0f || velocity.y != 0f || velocity.z != 0)
            {
                PlayerManager.Instance.FOVBlinders.FadeBlindersIn();
            }
            else
            {
                PlayerManager.Instance.FOVBlinders.FadeBlindersOut();
            }

            savedVelocity         = velocity;
            savedMovementVelocity = velocity - momentum;

            ResetInput();

            savedPlayerLocalPosition = Camera.main.transform.localPosition;
        }
Exemplo n.º 7
0
 public void CheckForGround()
 {
     m_mover.CheckForGround();
 }