- Home /
How to make a RigidBody move in a certain direction
Hello,
I am trying to make an android game and I am using Unity 5. I am trying to make touch controls for the player to move left and right. I have this:
function Start(){ if(Input.GetButtonDown(0)){ rigidbody.AddRelativeForce (-1, 0, 0); // 1 Unit left in local axes } }
Also it is giving me this error: Assets/TouchControls.js(2,23): BCE0017: The best overload for the method 'UnityEngine.Input.GetButtonDown(String)' is not compatible with the argument list '(int)'.
I honestly don't know what I did wrong. Any suggestions would be helpful. Thank You.
Tyler Butler
Answer by Priyanshu · Mar 29, 2015 at 08:18 AM
You Get the error because GetButtonDown method does not accept int as an argument, As the error says.
Argument is what you pass into the method. In your case its '0'.
Then what should i pass to make this work? Watch this tutorial.
But you said:
I am trying to make touch controls
Try to learn new Unity UI and you are good to go. You can find Tutorials here
Your answer
Follow this Question
Related Questions
Reading force on rigidbody? 1 Answer
AddForce not influenced by rotation 1 Answer
Gameobject is climbing out objects with rigidbody 0 Answers
Manually Apply Cars Collision Response Force 0 Answers
About Forces and Time.deltaTime 3 Answers