Pressing A and D moves my ship on its Z-axis

[SerializeField] float controlSpeed = 10f;
    void Update()
    {
        float xThrow = Input.GetAxis("Horizontal");
        float yThrow = Input.GetAxis("Vertical");

        float xOffset = xThrow * Time.deltaTime * controlSpeed;
        float newXPos = transform.localPosition.x + xOffset;

        transform.localPosition = new Vector3 (newXPos, transform.localPosition.y, transform.localPosition.z);
    }

This is my code. I couldn’t figure out on how to fix the issue. I used localPosition so it has to move on its X axis, not Z axis.

How do you have this object set up? I just tested your code and it’s moving on the X-Axis

What do you mean by that?

You said your ship is moving on the z-axis but you want it to move on the x-axis. I tested the code and it moves on the x-axis so, I am trying to figure out what your object looks like because when I test it, it works.

It looks like one of the star ship from the Argon Assault tutorial.

I want to know what the object hierarchy looks like in the scene. The ship is clearly not in the root (like mine), because then it would work (like mine). If I know what your hierarchy looks like, I can reproduce the issue and possibly provide a solution

Here

Perfect.

OK, so I had a little look and I think I could reproduce the problem. From the screenshot I could see that the ship is rotated 90 degrees. This didn’t make a difference because mine still moved correctly on the x-axis. Then I wondered why the ship is turned 90 degrees. I am making a huge assumption here, but I suspect your Player Rig object is rotated -90 degrees. If this is true, then that is your problem. When I rotated mine to -90, it started moving my ship on the z-axis.

So, to fix it without affecting the camera and ship: drag the camera and ship out of the Player Rig, rotate the Player Rig to 0, drag the camera and ship back into the Player Rig. Should be good

Made a quick gif of what I mean
fix
Don’t edit it in play mode like I did here

Unfırtunately, player rig had no rotation in it. So i will try to rotate the rig and reset the rotation of the ship to 0 and will try it that way. That seems to solve it. Thank you a lot!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms