예제 #1
0
    void Walk()
    {
        _walkStepParticles.enableEmission = true;

        walkDirection = Vector3.zero;

        if (ChainJam.GetButtonJustPressed(id, ChainJam.BUTTON.A))
        {
            animator.SetBool("Charge", true);
        }

        if (!ChainJam.GetButtonPressed(id, ChainJam.BUTTON.A))
        {
            animator.SetBool("Charge", false);
        }

        //lastStepTimer -= Time.deltaTime;
        //if (lastStepTimer <= 0)
        //{
        //	lastStepTimer = _stepTimeout;
        //	StartCoroutine(VibrateStep(0.1f));
        //}

        if (ChainJam.GetButtonPressed(id, ChainJam.BUTTON.LEFT))
        {
            walkDirection.x = -1;
        }
        else if (ChainJam.GetButtonPressed(id, ChainJam.BUTTON.RIGHT))
        {
            walkDirection.x = 1;
        }

        if (ChainJam.GetButtonPressed(id, ChainJam.BUTTON.DOWN))
        {
            walkDirection.z = -1;
        }
        else if (ChainJam.GetButtonPressed(id, ChainJam.BUTTON.UP))
        {
            walkDirection.z = 1;
        }

        rigidbody.AddForce(walkDirection.normalized * _walkSpeed);
        rigidbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, _maxWalkSpeed);

        transform.LookAt(transform.position + walkDirection);

        // switch back to standing
        if (walkDirection == Vector3.zero)
        {
            lastStepTimer    = 0;
            currentWalkState = Stand;
        }
    }
예제 #2
0
    void Update()
    {
        // X axis

        if (
            ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.LEFT))
        {
            axisX -= sensitivityX * Time.deltaTime;
        }
        if (ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.RIGHT))
        {
            axisX += sensitivityX * Time.deltaTime;
        }
        if (
            !ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.LEFT)
            &&
            !ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.RIGHT)
            )
        {
            axisX -= axisX * inertiaX * Time.deltaTime;
        }

        if (axisX > 1f)
        {
            axisX = 1f;
        }
        if (axisX < -1f)
        {
            axisX = -1f;
        }

        // Y axis

        if (
            ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.DOWN))
        {
            axisY -= sensitivityY * Time.deltaTime;
        }
        if (ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.UP))
        {
            axisY += sensitivityY * Time.deltaTime;
        }
        if (
            !ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.UP)
            &&
            !ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.DOWN)
            )
        {
            axisY -= axisY * inertiaY * Time.deltaTime;
        }

        if (axisY > 1f)
        {
            axisY = 1f;
        }
        if (axisY < -1f)
        {
            axisY = -1f;
        }

        //and the actual rotation!

        float rotationX = transform.localEulerAngles.y + axisX;

        rotationY += axisY;
        rotationY  = Mathf.Clamp(rotationY, minimumY, maximumY);

        transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);

        //jump
        if (ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.A))
        {
            GetComponent <PlayerJump>().JumpToRandomPlatform();
        }

        //shoot
        if (ChainJam.GetButtonJustPressed(GetComponent <Player>().id, ChainJam.BUTTON.B))
        {
            Shoot();
        }
    }