Joystick and character not matching up

Hey,

I have an issue where my joystick and character directions do not match, i think it might be because the character rotation is assuming portrait mode but the joystick is working on landscape IE

If i press up (landscape, joypad) the character moves in the correct direction but he is facing up (portrait )

I then flip the screen into portrait mode and when i press up on the joystick, the character moves in the correct direction but he is now facing up as if its landscape mode!

I think i need to adjust my code so that there is a 90 degree rotation in it so that forward on the joystick and character match but i have no idea, been at this for about 8 hours now, heres the code i’ve got (I’ve tried my best to limit this to just what is being used for the joystick) It’s a birds eye view, character should be able to turn 360 degrees and always facing the same as the joystick;

Thanks for any help!

using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections;
using System.Linq;
using UnityEngine.SceneManagement;

public class PlayerManager : MonoBehaviour{
    protected Joystick joystick;
    public enum ControlType {
	mouseCtrl,
	touchCtrl,
	keyboardCtrl,
        accelerometerCtrl,
        joystickCtrl,
    }

void Start (){
        joystick = FindObjectOfType<Joystick>();
	}

void Update (){
		if(!halt) {
	 		if(controlMode == ControlType.mouseCtrl || controlMode == ControlType.touchCtrl) {	 		
	 			touchInputManager();	 				
	 		}else if(controlMode == ControlType.accelerometerCtrl) {
                accelerometerInputManager();
            }else if(controlMode == ControlType.keyboardCtrl) {	 		
	 			keyboardInputManager();	 				
	 		}else if (controlMode == ControlType.joystickCtrl){
                joystickInputManager();
            }
        }
	}
private float turnSpeed = 180;
private float moveSpeed = 3;

void joystickInputManager()
    {
        var rigidbody = GetComponent<Rigidbody>();
        rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
        
        //this.transform.rotation = Quaternion.LookRotation(joystick.Horizontal * Vector3.right, Vector3.up);
        float inputZ = joystick.Horizontal;
        float inputX = joystick.Vertical;

        Vector3 lookDirection = new Vector3(inputX, 0, inputZ);
        Quaternion lookRotation = Quaternion.LookRotation(lookDirection, Vector3.up);

        float step = turnSpeed * Time.deltaTime;
        transform.rotation = Quaternion.RotateTowards(lookRotation, transform.rotation, step);
        rigidbody.velocity = new Vector3(joystick.Horizontal * moveSpeed + Input.GetAxis("Horizontal") * moveSpeed, rigidbody.velocity.y, joystick.Vertical * moveSpeed + Input.GetAxis("Vertical") * moveSpeed);
    }
}

, the character is always 90 degrees out of the direction im aiming for, IE if i want to go up, the character moves forward but the character is facing

Hey Everyone,

I went out for a walk got some nice fresh air and came back to this, to sort my issue i just changed this line here

         Vector3 lookDirection = new Vector3(inputX, 0, inputZ);

To this

Vector3 lookDirection = new Vector3(inputZ, 0, inputX);

Good 8 hours on this trying to figure it out, tons and tons of youtube videos, etc and i just had to swap them about, seams so obvious now!

hah, Thanks!