How to move an object along the X and Z axis with arrow keys/wasd with javascript?

Ok, so i had this working, but then i accidentally deleted it and can't seem to get it working again. I want my cube to move along the X axis with the left and right arrow keys or a and d keys, and along the Z axis with the up/down or w/s keys. I've googled a bit and see no reason why this wouldn't work. Anyway, here's my code:

var speed : float = 5; var x : float; var z : float;

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

Thanks in advance :)

Hi,

It's UpperCase for Update()

Silly isn't it.... :) Often do that error myself...

The best way to go about that kind of bugs, is to cut down the problem. Make use of Debug.Log() or use the debugger itself and put breakpoints. Then you would find that your method is not called and then can deduce is not the right one.

var speed : float = 5;
var x : float;
var z : float;

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