0
Movement coding
I need help.......?I am trying to make game from unity but I do my code and nothing happens if someone could give me a working movement with the keys being wasd. I would really appreciate I. thank you
6 Réponses
+ 1
Use Debug.log() to write info about the variables. It will be good debugging practice
0
Can you post the code?
0
This is an official unity tutorial. They can be very useful
https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial/moving-player
0
But the gist is (you may need to change the Y and Z coords depending on how the game is set up.) change the speed until it feels right
float speed = 5.0f;
void Update(){
newX =player.position.x;
newY =player.position.y;
if(Input.GetKey(KeyCode.W)){
newX += speed * Time.deltaTime;
}
if(Input.GetKey(KeyCode.S)){
newX -= speed * Time.deltaTime;
}
if(Input.GetKey(KeyCode.A)){
newY += speed * Time.deltaTime;
}
if(Input.GetKey(KeyCode.D)){
newY -= speed * Time.deltaTime;
}
player.position = new Vector3(newX,newY,player.position.y)
}
0
thank u guys I don't have code on my mobile but no errorson the console but when I hit play my person doesn't move
0
oh okay BC I have tried and tried to rewright my code but every time its the same thing!!!!!so use debug.log()