So, I’ve got my Character Controls working, as well as the rotation.
However, they don’t seem to like each other, and if I go left, my Character faces left, but moves forward (like a crab, lol).
If I press down, the character seems to walk backwards.
This is what I have:
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Winp.GetButtonDown(WiiUGamePadButton.ButtonA) || Input.GetKeyDown(KeyCode.Space)) {
moveDirection.y = jumpSpeed;
}
if (Input.GetAxis("Horizontal") < 0) {
transform.eulerAngles = new Vector3(0,-90,0);
}
if (Input.GetAxis("Horizontal") > 0) {
transform.eulerAngles = new Vector3(0,90,0);
}
if (Input.GetAxis("Vertical") < 0) {
transform.eulerAngles = new Vector3(0,180,0);
}
if (Input.GetAxis("Vertical") > 0) {
transform.eulerAngles = new Vector3(0,0,0);
}
}
So my question is, if I want to go left, the Character needs to face left, and go left.
How can I accomplish this?
Update
I’ve Updated my Code to this:
if (controller.isGrounded) {
transform.forward = Vector3.Normalize(new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical")));
moveDirection = transform.forward;
moveDirection *= speed;
if (Winp.GetButtonDown(WiiUGamePadButton.ButtonA) || Input.GetKeyDown(KeyCode.Space)) {
moveDirection.y = jumpSpeed;
}
Debug.Log(moveDirection);
}
At first, it looked like it worked, but since it’s “transformer.forward”, it will always go forward.
Update 2
I think I’m getting closer now, as I’ve managed to make Vertical Controls work perfectly.
if (controller.isGrounded) {
transform.forward = Vector3.Normalize(new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical")));
moveDirection = transform.forward;
if (Input.GetAxis("Vertical") == 0) {
moveDirection *= 0;
}
else {
moveDirection *= speed;
}
if (Winp.GetButtonDown(WiiUGamePadButton.ButtonA) || Input.GetKeyDown(KeyCode.Space)) {
moveDirection.y = jumpSpeed;
}
Debug.Log(moveDirection);
}
However, the Horizontal movement is now always 0, unless I use the Vertical Axis while using the Horizontal Axis.
So, any quick solution to this one?

After changing "var" into "float", it looks like it works. I currently can only go into 4 directions because of this change, but the Character is meant to be controlled by an Analog Stick, making it very unconfty. Changing "transform.forward" into "transform.TransformDirection(moveMag)" gave me another error. In order to accomplish that, I have to change "float" into "Vector3", but Unity3D gives me yet another error for that.
– Yamilla