Controlling with scripts.

Hello, as you know i´m new to programming, well not so new, i was programing with python before, but javascript is new for me at least. I wrote a script to make camera moves with keys W,A,S,D.

The camera tutorial ran well, and understood perfectly, but i looked that Vertical Axis of the camera is not the same to the Vertical´s objects ones. So if i want to move an object, the script does not work well, since the camera uses X and Z to move left, right, back, forward. The objects use X and Y, so with that script, the objects move left, right, up and down. Well, i fixed that by changing order, let say, for camera (X, 0, Z), for objects used (X, Y, 0). At the moment all is clear.

But there is something that i can´t understand well yet, when i set the script to move the camera with this script :

var speed = 5.0;
function Update () {
var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
transform.Translate(x, 0, z);}

Why we write a “Vertical” string if we are moving the camera along the left, right, forward, backward ?. There are no Up and Down movements…

Thank you!.

PD. If you have or link me a tutorial to understand this, you will help me too much…

Better this :

i´m looking for a script that controls the object with conditions…

For instance:

If press W :
 traslate the object Y Axis positively

if press S :
 traslate the object Y Axis negatively

if press A :
 rotate the object X Axis negatively

if press D :
 rotate the object X Axis positively

I think something like this will be more well arranged and easy to understand… is better than 1st code above.´

Excuse me if this is easy, i´m starting with js. Thank you.

Vertical in this case just stands for the up/down keys. The actual movement takes place in transform.Translate(x, 0, z)

Note that the y axis (vertical movement) is set to 0 here.

The strings you use in GetAxis are mapped to the appropriate entries in the Input Settings.

Actually it’s quite a bit worse, because you would be hard-coding the keys and adding redundant code unnecessarily. Using GetAxis takes care of most of the functionality for you.

–Eric

Finally i understood the system, i made two script files, one for move and one for rotate. This way works perfect. :stuck_out_tongue: