Beispiel #1
0
    private void FixedUpdate()
    {
        Launching();
        Bouncing();
        Boosting();
        OnMovingObject();


        if (!_controller.dead)
        {
            currentState = CurrentState.alive;
            if (_movementEnabled)
            {
                _controller.Move(_cubeInfoSO.speed + _extraSpeed + _movingObjectDirection.x, _moveDirection);

                if (!_holdingJump)
                {
                    _controller.Step(_moveDirection, 1f);
                }
                if (_groundJumpActive && !_inLauncher && !_inBouncer)
                {
                    _controller.Jump(_realJumpForce, _holdingJump, ref _distanceReached);
                }
            }
        }
    }
Beispiel #2
0
    void CalculatePosition()
    {
        if (controller.collisions.shouldReflect)
        {
            velocity.x = -velocity.x * bounceDampening;
        }

        if (controller.collisions.shouldReflectY)
        {
            velocity.y = -velocity.y * bounceDampening;
        }

        if (Mathf.Abs(velocity.x) > friction * Time.deltaTime)
        {
            velocity.x -= Mathf.Sign(velocity.x) * ((controller.collisions.below) ? friction : ((isDangerous) ? dangerousDrag : drag)) * Time.fixedDeltaTime;
        }
        else
        {
            velocity.x = 0.0f;
        }

        velocity.y -= gravity * Time.fixedDeltaTime;

        //move
        controller.Move(velocity);

        if (controller.collisions.above)
        {
            velocity.y = 0f;
        }

        if (controller.collisions.below)
        {
            velocity.y = 0f;
        }

        Squash(velocity, lastVelocity);

        if ((int)(velocity.x * 100) != (int)(lastVelocity.x * 100))
        {
            lastVelocity.x = velocity.x;
        }

        if ((int)(velocity.y * 100) != (int)(lastVelocity.y * 100))
        {
            lastVelocity.y = velocity.y;
        }
    }