- Home /
Question by
$$anonymous$$ · Nov 24, 2013 at 06:47 PM ·
rotationjavascriptmovementsprite
Movement and aiming based on Arrow keys and WASD?
Hello, I am currently working on a top-down shooter in which I want the player to be able to move with the WASD keys and to aim with the arrow keys. I am working in 2D space with a simple sprite. So far, I have the player movement, but not the aiming;
#pragma strict
var moveSpeed : float = 10F;
function Start () {
}
function Update(){
transform.Translate(Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime,Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime,0);
}
I want the player to point in the direction corresponding to the key that is pressed; ie. Right arrow pressed, faces right. (Yes, I am a MAJOR n00b at this, sorry.) Can anyone please help? Thanks!
Comment
Ok use rotate and setup a input similar to vertical and horizontal. There is gonna be a bug because the vertical and horizontal use arrow keys and wasd. Also use character controller move function to move so you don't go through walls.