- Home /
Move the rigidbody with keys
I'm sorry that this is probably an idiotic question, but I just can't find the mistake!
Here is a small script which should allow the player to move with key inputs.
void Update(){
Vector3 movedir = new Vector3(Input.GetAxis ("Horizontal"),0, Input.GetAxis ("Vertical"));
print (movedir);
rigidbody.AddForce (movedir);
}
But it dosen't work! :(
Answer by AlucardJay · Apr 02, 2014 at 02:35 PM
It does work :) the problem is you are applying a very small amount of force. Try multiplying the movedir by an amount to apply a greater amount of force :
public float forceAmount = 200f;
void Update(){
Vector3 movedir = new Vector3(Input.GetAxis ("Horizontal"),0, Input.GetAxis ("Vertical"));
print (movedir);
rigidbody.AddForce (movedir*forceAmount);
}
in future, please format your code by highlighting the code and clicking the 101010 button
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Making a bubble level (not a game but work tool) 1 Answer
Why does my character keep sliding around? Help! (Rigid Body) 1 Answer
Moving a Rigidbody Relative to Camera Direction 0 Answers
Character moving forwards before pressing anything 0 Answers