0
\$\begingroup\$

How can i change my movement for mobile i think left and right gonna work but i don't know what should i do for jump

private void Update()
{

    vector = Vector3.zero;

    if (characterController.isGrounded)
    {
        /*verticalVelocity = -gravity * Time.deltaTime*/;
        verticalVelocity = -0.5f;

        if (Input.GetKeyDown(KeyCode.V))
        {
            verticalVelocity = jump;
        }
    }
    else
    {
        verticalVelocity -= gravity * Time.deltaTime;
    }

    vector.x = Input.GetAxisRaw("Horizontal") * speed;
    if (Input.GetMouseButton(0))
    {
        if (Input.mousePosition.x > Screen.width / 2)
            vector.x = speed;
        else
            vector.x = -speed;
    }
    vector.y = verticalVelocity;
    vector.z = speed;

    characterController.Move(vector * Time.deltaTime);
}

I solved the problem this way

if (characterController.isGrounded)
    {

        verticalVelocity = -0.5f;

        if (Input.GetMouseButton(0))
        {
            if (Input.mousePosition.y > Screen.height / 2)
            {
                verticalVelocity = jump;
            }
            else
            {
                verticalVelocity = -jump;
            }
        }
    }
    else
    {
        verticalVelocity -= gravity * Time.deltaTime;
    }

    vector.x = Input.GetAxisRaw("Horizontal") * speed;
    if (Input.GetMouseButton(0))
    {
        if(Input.mousePosition.y < Screen.height / 2)
        {
            if (Input.mousePosition.x > Screen.width / 2)
                vector.x = speed;
            else
            {
                vector.x = -speed;
            }
        }
    }
\$\endgroup\$
6
  • 1
    \$\begingroup\$ How do you want your game to be played on mobile? What have you tried so far to achieve that goal? \$\endgroup\$ Commented Feb 20, 2019 at 14:35
  • \$\begingroup\$ I fixed the problem \$\endgroup\$ Commented Feb 20, 2019 at 14:51
  • \$\begingroup\$ Want to share your solution as an answer to help others with similar issues? Or would you prefer to just delete the question if it's no longer needed? \$\endgroup\$ Commented Feb 20, 2019 at 23:26
  • \$\begingroup\$ I can share, no problem. I didn't test with a mobile device yet, but probably it's gonna work \$\endgroup\$ Commented Feb 21, 2019 at 7:52
  • \$\begingroup\$ Don't edit your solution into the question. Post it as an answer. (The "Your Answer" box on desktop, or "Add an Answer" button on the app) \$\endgroup\$ Commented Feb 21, 2019 at 12:27

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.