- Home /
Reversed Controls?
im working on a 2d platformer and when a attach my movement script the controls are reversed left left arrow goes right and the right arrow goes left!
my script:
var playerSpeed : int;
function Update () {
// amount to move player
amtToMove = (playerSpeed*Input.GetAxis("Horizontal")) *Time.deltaTime;
//move/translate the player
transform.Translate(Vector3.right*amtToMove);
}
Answer by skovacs1 · Aug 19, 2010 at 05:16 PM
Either you are negating the axis or your camera is looking down the wrong end of the Z axis for that code to work as you expect.
Rotate everything in your scene by 180 degrees to fix the problem. An easy way to do this is to add an empty gameObject, drop everything onto it. Rotate by 180 degrees, then drag them off and delete it.
Alternatively you could do something like using mainCamera.transform.right or one of the player axes like transform.forward (as appropriate) in stead of the global Vector3.right.
Thanks i guess this question just involved "common sense"!
Answer by Wolfram · Aug 19, 2010 at 06:00 PM
Vector3.right is always (1/0/0), you want to use the right-Vector of your current transform instead:
transform.Translate(transform.right*amtToMove);
Since you said this is a 2D-game, and you are certain the camera orientation/the player never rotates (so "right" is always the same "right), then you can keep your version, and simply add a sign:
transform.Translate(Vector3.right*(-amtToMove));
Your answer
