- Home /
Need a help for movement Script!
Hi everybody, i'm making a game with 2 player on PC, and i need to configure the movement like that : Player 1 play with the "WASD keys" and player 2 with "Arrow keys (left,right,up,down)".. but i don't know how to do my script, Vector3 or 2 ? i need help plz.. if possible give me an example of what i need to do plz..
P.S: My game is not in 1 person, it's like a PacMan Style. Thanks.!
Answer by azmat786n · Dec 01, 2012 at 11:21 PM
//player one script
var moveSpeed:float = 10.0f;
function Update() {
if(Input.GetAxis("Horizontal")||Input.GetAxis("Vertical"))
{
transform.Translate(Input.GetAxis("Horizontal") * moveSpeed,Input.GetAxis("Vertical")* moveSpeed,0)
}
}
player 2
//player2 script
var moveDir:Vector3 = Vector3.zero;
function Update() {
//move left
if (Input.GetKey(KeyCode.A))
{
moveDir.x = -5;
}
//move right
else if (Input.GetKey(KeyCode.D))
{
moveDir.x = 5;
}
//move down side
else if (Input.GetKey(KeyCode.S))
{
moveDir.y = -5;
}
//move up side
else if (Input.GetKey(KeyCode.W))
{
moveDir.y = 5;
}
else
{
//if not pressed any key
moveDir.x = 0;
}
//start movement
transform.Translate(dir * Time.smoothDeltaTime);
}
i hope this is helpful
But, i have test your script and the playerone, pass into all my wall, and move very fast.. and the player 1 and 2 does not go foward and backward, they go up and down trought my floor.
decrease the movespeed float and do your walls have collider ?
Your answer
![](https://koobas.hobune.stream/wayback/20220613084816im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Set up a 3D fly through 4 Answers
TERA style movement 1 Answer