예제 #1
0
    // Update is called once per frame


    void FixedUpdate()
    {
        bool touchingGround = checkGround.OnGround(collider);

        if (touchingGround && jumpAvailable)
        {
            if (Input.GetKeyDown(KeyCode.Space) && anim.GetBool("roll") == false)
            {
                print(touchingGround);
                //print("jumping up");
                anim.SetBool("jump", true);
                rb.AddForce(Vector2.up * jumpSpeed);
            }
        }
        else if (!jumpAvailable && touchingGround)
        {
            //print("landing");
            anim.SetBool("jump", false);
            jumpAvailable = true;
        }
        else if (jumpAvailable && !touchingGround)
        {
            jumpAvailable = false;
            //anim.SetBool("jump", true);
        }
    }
예제 #2
0
    void FixedUpdate()
    {
        bool touchingGround = checkGround.OnGround(colliderBox);

        if (Input.GetKeyDown(KeyCode.S))
        {
            if (touchingGround && !inRoll)
            {
                startTime = Time.time;
                anim.SetBool("roll", true);
                anim.SetBool("run", false);
                inRoll           = true;
                colliderBox.size = new Vector2(colliderBox.size.x, colliderBox.size.y / 2);
                print(rb.velocity);
                rollPusher.force = new Vector2(dirCheck.getDirection() * rollSpeedX, 0);
            }
        }


        else if (inRoll && Time.time - startTime > rollDuration)
        {
            inRoll = false;
            print("roll should have ended");
            colliderBox.size = new Vector2(colliderBox.size.x, colliderBox.size.y * 2);
            rollPusher.force = new Vector2(0, 0);
            rb.velocity      = new Vector2(0, rb.velocity.y);
            anim.SetBool("roll", false);
        }
    }
예제 #3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (canCrowdHop)
        {
            CheckForCrowd();
        }

        _gravPull = _cGrav.gravitationalPull;


        if (_input && _GChecker.OnGround())
        {
            Jump(jumpForce);
        }
        else if (_GChecker.OnGround())
        {
            // Was moving vertically before hitting ground
            if (_mov.y != 0)
            {
                OnLandAirtimeEvent.Invoke(_airTime);
                OnLandEvent.Invoke();
            }


            _fact.x  = 1;
            _fact.z  = 1;
            _mov.y   = 0;
            _mov.z   = 0;
            _airTime = 0;
        }

        if (!_GChecker.OnGround())
        {
            _airTime    += Time.deltaTime;
            _bonkingHead = _GChecker.CheckRay(bonkCheckRayOrigin, transform.up, bonkCheckRayRange);
        }

        if (_bonkingHead)
        {
            _fact.x = 1;
            _mov.y  = 0;
        }

        MovementVector = _mov;
        FactorVector   = _fact;
    }
예제 #4
0
    private void FixedUpdate()
    {
        if (!_GChecker.OnGround(gravStoppers))
        {
            // print("airTime");
            StartCoroutine(ApplyGravity());
        }
        else
        {
            //print("groundTime!");
            StopCoroutine(ApplyGravity());

            _mov.y       = 0;
            _timeFalling = 0;
        }

        Vector3 fac = FactorVector;

        FactorVector   = fac;
        MovementVector = _mov;
    }
예제 #5
0
    // Update is called once per frame
    void Update()
    {
        if (canCrowdRun)
        {
            if (_GChecker.CheckRay(out _rayhit, crowdColliderLayer))
            {
                _newCrowdCollider = _rayhit.collider;
            }
            else
            {
                _newCrowdCollider = null;
            }

            _onCrowd = (_currentCrowdCollider || _newCrowdCollider);
            if (_GChecker.OnGround())
            {
                _onCrowd = false;
                _currentCrowdCollider = null;
            }

            /* else //If I have begun crowd running, i only stop when on ground
             *   _onCrowd = !_GChecker.OnGround();*/

            if (_onCrowd)
            {
                CrowdContact(_newCrowdCollider);

                if (_inContactComponent)
                {
                    // multiply by constant to make it more user friendly to
                    // evaluate
                    _inContactComponent.EvaluateVelocity(
                        (_velocity * _currentVelMod).magnitude * 10);
                }

                if (_slowDownTimer >= timeBeforeSlowDown.Value)
                {
                    // How much has it gone since the slowdown started
                    float currSlow = _slowDownTimer - timeBeforeSlowDown;


                    // Check the curve to get the modifier for the speed [0-1]
                    _currentVelMod =
                        crowdVelocityModifier +
                        slowDownCurve.Value.Evaluate(currSlow / crowdDecelerationTime);
                    // print("VEL MOD:" + _currentVelMod);
                }
                else
                {
                    _currentVelMod = 1;
                }
            }
            else
            {
                _slowDownTimer = 0;
                _currentVelMod = 1;
            }
        }

        AccelerateX();
        AccelerateZ();

        FactorVector   = Vector3.one;
        MovementVector = _velocity * _currentVelMod;
    }