Character Movement by World Coordinates

Hello there!

I’ve just tried to make a character controller which would move the character based on the world coordinates. It’s an game from isometric view with a fixed camera orientation, like in Secred of Mana on SNES.

I’ve already experimented a bit with first person and 3rd person cameras and they are quite easy to implement (at least there are plenty of tutorials and examples out there), but haven’t found one for isometric games with a fixed camera orientation.

	// Update is called once per frame
	void Update () {
		// update movement only when the character is grounded
		if(charController.isGrounded == true) {
			float horizontal = Input.GetAxis("Horizontal");
			float vertical = Input.GetAxis("Vertical");

			// Display idle animation if the axis are below deadzone
			if(Mathf.Abs(vertical) < deadZoneTolerance  Mathf.Abs(horizontal)< deadZoneTolerance) {
				animation.CrossFade("idle");
				return;
			} else {
				if(Input.GetButton("Run")) {
					animation.CrossFade("run");
					walkSpeed = 4;
				} else {
					animation.CrossFade("walk");
					walkSpeed = 1;
				}
			}
			
			// Create an animation cycle for when the character is turning on the spot
			if(horizontal!=0.00  vertical==0.00) {
				//animation.CrossFade("walk");
			}
			
			moveDirection = new Vector3(horizontal,0,vertical);
			moveDirection = transform.TransformDirection(moveDirection);
		}

		moveDirection.y -= gravity * Time.deltaTime;
		charController.Move(moveDirection * (Time.deltaTime * walkSpeed));
	}

That’s what I’ve tried so far, but it’s not working as expected, as it still moves the character based on local coordinates. This is my main problem so far. The other would be to rotate the char in the direction it’s walking depending on the value of Horizontal/Vertical axes. After the first person/3rd person code I thought this one would be similary easy, but seems I was wrong…

Anyone got any ideas how to do it?

Does your :charController.Move() operate in local or world space?

You are doing topdown right?

Why are you moving on the Z Axis?

moveDirection = new Vector3(horizontal,0,vertical);
moveDirection = transform.TransformDirection(moveDirection);

Try moving on the Y axis and than for jumping use the Z axis.

Well, obviously it does in local space, as the char always moves relative to it’s direction instead of the world axes. But i don’t know where to change it, I’ve just added the Character Controller from Component > Physics > Character Controller to my player model and the script from above

convert from worlds space to object space before passing to Move() (syntax may be a bit off, working from memory)

see:

actually, I think you can just get rid of this line:
moveDirection = transform.TransformDirection(moveDirection);
by doing so you will leave the moveDirecition in worldSpace.

Right. Thanks ^^

Guess I have to get a better with transforms and that stuff. Is there a good Tutorial on transformations/rotations etc. over there (preferably in unity, but basic tutorials should do it too)?