x


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);

}

more ▼

asked Aug 19 '10 at 05:02 PM

john 2 gravatar image

john 2
75 29 35 46

is playerSpeed positive?

Aug 19 '10 at 05:06 PM skovacs1
(comments are locked)
10|3000 characters needed characters left

2 answers: sort oldest

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.

more ▼

answered Aug 19 '10 at 05:16 PM

skovacs1 gravatar image

skovacs1
10k 11 25 92

Thanks i guess this question just involved "common sense"!

Aug 19 '10 at 05:34 PM john 2
(comments are locked)
10|3000 characters needed characters left

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));
more ▼

answered Aug 19 '10 at 06:00 PM

Wolfram gravatar image

Wolfram
9.1k 8 20 53

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5273
x1071
x230

asked: Aug 19 '10 at 05:02 PM

Seen: 1050 times

Last Updated: Aug 19 '10 at 05:02 PM