- Home /
Question by
Zombat96 · Feb 15, 2013 at 03:16 AM ·
javascriptpong
Pong game: how to make the AI paddle move up and down (Javascript)
i am making my first game and know NOTHING about scripting. Ive gotten the paddle to move up but it justs moves off on the Y axis infinitely and leaves the cameras view. i would appreciate any help on how to make the paddle stop at a certain point and come back down on the Y axis.. this is what ive got so far..
function Start () {
}
function Update () { transform.Translate(0,.1,0);
}
this is assigned to the cube game object.. thanks in advance
Comment
Best Answer
Answer by robertbu · Feb 15, 2013 at 04:48 AM
Here is something simple that uses arrow keys:
var trans : float = 0.05;
function Update ()
{
if (Input.GetKey(KeyCode.LeftArrow))
transform.Translate(-trans, 0,0);
if (Input.GetKey(KeyCode.RightArrow))
transform.Translate(trans,0,0);
if (Input.GetKey(KeyCode.UpArrow))
transform.Translate(0,trans,0);
if (Input.GetKey(KeyCode.DownArrow))
transform.Translate(0,-trans,0);
}