- Home /
make a bouncing ball move slightly to the left or right,
hello, i am trying to make a ball bounce either to the left or right, The ball is set up as a rigid body and i have also created a bouncy material so that it always bounces at the same height,but i would like it to move fractionally to the left or right, any idea how i would accomplish this, thanks
Answer by Joeltron · Feb 08, 2017 at 09:28 AM
Something like this....?
void Update () {
if (Input.GetKey (KeyCode.A)) {
rigidbody.AddForce (transform.right * (-power));
}
if (Input.GetKey (KeyCode.D)) {
rigidbody.AddForce (transform.right * (power));
}
the drag setting should stop motion after the initial force (as long as you arent holding down A or D. if you just want it to move on a single press it could be Input.GetKeyDown power can be any float value, probably public so you can adjust it as necessary.
Your answer
![](https://koobas.hobune.stream/wayback/20220612110603im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to update the Unity part included into an android native application ? 0 Answers
how to make ball rolling forward while follows a curve track? 0 Answers
My app freezes on specific y coordinates 0 Answers
Unity Editor not installing from unity hub.,Unity Editor is not installing from unity hub. 0 Answers
Android Native Screenshot function creats black Image 1 Answer