Isometric Controls

Hi, I seem to have encountered an issue in my isometric 3rd person game where If the analogue stick is pointed upwards, the player moves positively along the virtual Z axis, I would like the player to move along a virtual Z axis that is relative to the isometric view.

My Camera’s rotation vector is (30,45,0)

In my head when I try to fix this problem I think I should just perform some calculation involving the angle difference but thought I’d ask you guys before I start so I don’t reinvent the wheel :slight_smile:

Thanks in advance

Code :

        direction = new Vector3(joyScript.position.x, 0, joyScript.position.y);
        if (direction.magnitude > 0.1f)
        {
            rotation = Quaternion.LookRotation(direction, Vector3.up);
            transform.rotation = rotation;
            ps3move = ps3speed * Time.deltaTime * direction.magnitude;
            transform.position += transform.forward * ps3move;
            playerModel.animation.Play("runforward");
        }

High Quality Image below

alt text

Add these member variables to your script:

Vector3 forward;
Vector3 right;

On the Start() function set them like this:

void Start () {
		forward = Camera.mainCamera.transform.forward;
		forward. y = 0;
		forward = Vector3.Normalize(forward);
		right = Quaternion.Euler(new Vector3(0,90,0)) * forward;
	
	}

This is assuming your camera angle doesn’t change. If it does, you have to run this code again to update the unit vectors.
Replace your code with this:

direction = new Vector3(joyScript.position.x, 0, joyScript.position.y);
        if (direction.magnitude > 0.1f)
        {
			Vector3 rightMovement = right * ps3speed * Time.deltaTime * joyScript.position.x;
			Vector3 upMovement = forward * ps3speed * Time.deltaTime * joyScript.position.y;
         
			Vector3 heading = Vector3.Normalize(rightMovement+upMovement);
			transform.forward = heading;
            transform.position += rightMovement;
			transform.position += upMovement;			
            playerModel.animation.Play("runforward");
        }

It’s similar to the code I posted on the link above. If you need an explanation read through that link and it might help or you can ask again here.

Edit: Adding the link here as it seems to have disappeared into nested comments of doom. http://answers.unity3d.com/questions/561631/adapt-orientation-of-player-controls-to-camera.html