- Home /
Question by
$$anonymous$$ · Feb 28, 2014 at 12:39 AM ·
javascriptmovement
Help with movement script
I wrote this script so that my character could move up down left and right, yet it gives me an error when I add it into unity. Thanks for any help!
#pragma strict
function Start () {
}
function Update () {
if
(var xI : float = Input.GetKeyDown (KeyCode.A) * Time.deltaTime * 0.5);
transform.Translate (Vector3(xI,0,0));
if
(var xII : float = Input.GetKeyDown (KeyCode.D) * Time.deltaTime * -0.5);
transform.Translate (Vector3(xII,0,0));
if
(var yI : float = Input.GetKeyDown (KeyCode.W) * Time.deltaTime * 0.5);
transform.Translate (Vector3(0,yI,0));
if
(var yII : float = Input.GetKeyDown (KeyCode.S) * Time.deltaTime * -0.5);
transform.Translate (Vector3(0,yII,0));
}
Comment
Each error is about an unexpected token, yet since I'm new to this I'm not sure what to do.
Best Answer
Answer by MrProfessorTroll · Feb 28, 2014 at 01:48 AM
var speed : float = 1;
var h :float = Input.GetAxis("Horizontal");
var v : float = Input.GetAxis ("Vertical");
var moveDir : Vector3 = Vector3 (h, v, 0);
moveDir *= Time.deltaTime * speed;
transform.Translate (moveDir);
Answer by LilacGear · Feb 28, 2014 at 01:06 AM
#pragma strict
function Start () {
}
function Update () {
if
(var xI : float = Input.GetKeyDown ("A") * Time.deltaTime * 0.5);
transform.Translate (Vector3(xI,0,0));
if
(var xII : float = Input.GetKeyDown ("D") * Time.deltaTime * -0.5);
transform.Translate (Vector3(xII,0,0));
if
(var yI : float = Input.GetKeyDown ("W") * Time.deltaTime * 0.5);
transform.Translate (Vector3(0,yI,0));
if
(var yII : float = Input.GetKeyDown ("S") * Time.deltaTime * -0.5);
transform.Translate (Vector3(0,yII,0));
}
codeings not my strong suit but this should work
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
whay cant i move with this script???? 3 Answers
qrest system 1 Answer
Expecting ':' Found '=' Error 1 Answer
AssetBundle Android 1 Answer