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\$
  • 1
    \$\begingroup\$ How do you want your game to be played on mobile? What have you tried so far to achieve that goal? \$\endgroup\$ – DMGregory Feb 20 at 14:35
  • \$\begingroup\$ I fixed the problem \$\endgroup\$ – duhaonur Feb 20 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\$ – DMGregory Feb 20 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\$ – duhaonur Feb 21 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\$ – DMGregory Feb 21 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.