3
\$\begingroup\$

I'm learning Unity. I'm making a 2D top down Frogger-esque game. I was wondering how you would go about making the player move x pixels per button press.

I have this code to move him, currently with a float for x and y inputs, so he moves slowly:

    Vector2 movement_vector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

    if (movement_vector != Vector2.zero)
    {
        anim.SetBool("isWalking", true);
        anim.SetFloat("input_x", movement_vector.x);
        anim.SetFloat("input_y", movement_vector.y);
    }
    else
    {
        anim.SetBool("isWalking", false);
    }

    rbody.MovePosition(rbody.position + movement_vector * Time.deltaTime);
\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

I think the best way to approach this would be to create a grid system where each square is 64x64 pixels, and then have your button press increment the square number. So the frog technically moves 64 pixels, but in code all you'd be doing is saying gridSquaresX + 1 or something.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .