Ejemplo n.º 1
0
    void MovePosition()
    {
        float temp1, temp2;

        temp1 = horizontal;
        temp2 = vertical;
        if (Mathf.Abs(temp1) < 0.25 && Mathf.Abs(temp2) < 0.25)
        {
            speed = 2.5f;
        }
        else
        if (Mathf.Abs(temp1) < 0.5 && Mathf.Abs(temp2) < 0.5)
        {
            speed = 5f;
        }
        else
        {
            speed = 10f;
        }

        Vector3 rotation = joystick.DirectionToRotate();

        if (rotation != Vector3.zero)
        {
            body.rotation = Quaternion.Euler(body.transform.rotation.x, rotation.y, body.transform.rotation.z);
        }

        Vector3 movement = new Vector3(horizontal, 0, vertical);

        movement = movement.normalized * speed * Time.deltaTime;
        rb.MovePosition(rb.position + movement);
    }