Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

How do add force to the left (x-axis)

$
0
0
I am very new to unity, and I created a very simple 2d "game" in which a ball falls from a height and lands on platforms. I was successfully able to script the ball in Javascript to move right upon user input. For some reason though, I cannot let the user add force to the left no matter what I try. I know this must be painfully simple and stupid, so many thanks to whoever deigns to answer this. The code is below Original without force to the left; works perfectly: #pragma strict function FixedUpdate () { if (Input.GetKey ("right")) rigidbody2D.AddForce(Vector2.right * 10); } My failed attempt to implement left movement: #pragma strict function FixedUpdate () { if (Input.GetKey ("right")) rigidbody2D.AddForce(Vector2.right * 10); } function FixedUpdate () { if (Input.GetKey ("left")) rigidbody2D.AddForce(Vector2.(0,-1) * 10); } Thank you again

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>