How to move along the z axis from Top-Down Perspective?

Hey guys, I’ve decided to make my 2D game play along the x and z axis, so i can make use of things like the navmesh. But i dont know how to make my character move forward and backward. The movement script looked like this when i used the default 2D view.

    void Update ()
    {
        transform.position += new Vector3(Input.GetAxis ("Horizontal"), Input.GetAxis ("Vertical"), 0.0f) * Time.deltaTime * speed;
    }
}

But this obviously doesn’t work because my character tries to move up in the air now from the new angle. Can someone help me change this?

Well, your vector says new Vector3(x,y,z) , so Horizontal goes to x, and vertical to y. z stays at zero. So you should assign your horizontal or vertical thing to the z axis instead of y.

1 Like

I wanted to mate, but the unity input manager doesn’t seem to have the option. It has x and y, and then 3 to 20th joystick axis (and I don’t even really know what those mean).

The controller input for the joystick is horizontal x and vertical y. You need to assign the axis within your code, not search for a z axis in the joysticks, as this would be a fancy controller :wink:

You have got your right left joystick assigned to x and top down joystick assigned to y.

        transform.position += new Vector3(Input.GetAxis ("Horizontal"), Input.GetAxis ("Vertical"), 0.0f) * Time.deltaTime * speed;

but you need to assign your up and down joystick to z, so:

        transform.position += new Vector3(Input.GetAxis ("Horizontal"), 0.0f, Input.GetAxis ("Vertical")) * Time.deltaTime * speed;

As I do not know your specific environment, this is just a suggestion, hope it helps you.

2 Likes

Dude! I can’t believe I didn’t realize this. Thank you so much. It was ages ago that I wrote that down as I followed a tutorial and I completely forget those values are for each individual axis. Z was set to 0.0f (facepalm).

1 Like

And a Tip Jaxobz use Character Controller instead :wink:

1 Like