- Home /
Moving right and up instead of just up.
if(Input.GetKey(rightKey) && (upKey)){
rigidbody2D.velocity.x = moveSpeed;
rigidbody2D.velocity.y = flySpeed;
print("Flying up-right");
}
That code is in the update function. When i press my upKey it goes right and up. i want it to just go up.
else if(Input.GetKey(rightKey)){
rigidbody2D.velocity.x = moveSpeed;
}
else if(Input.GetKey(leftKey)){
rigidbody2D.velocity.x = moveSpeed * -1;
}
else if(Input.GetKey(upKey)){
rigidbody2D.velocity.y = flySpeed;
}
Thats the rest of my code for moving.
Comment
Answer by mattyman174 · Feb 22, 2014 at 02:42 AM
Have them all in their own IF Statements, no IF ELSE and remove your first IF.
if(Input.GetKey(rightKey)){
rigidbody2D.velocity.x = moveSpeed;
}
if(Input.GetKey(leftKey)){
rigidbody2D.velocity.x = moveSpeed * -1;
}
if(Input.GetKey(upKey)){
rigidbody2D.velocity.y = flySpeed;
}
Your answer

Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Move Object Smoothly 1 Answer
Problem with Pause and Pause Menu Script 1 Answer
How to make basic AI in a 2d game? 4 Answers
Scripting object movement? 1 Answer