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

Can't seem to use AddForce

$
0
0
Just trying to use AddForce to add an upwards force to an instantiated sphere. Must be something I'm leaving out or not coding properly. Here's my code. Note: touchLength is a variable which will have a value between 1 and 250, usually closer to 250. void Update () { if (Input.touchCount == 1) { if (Input.GetTouch(0).phase == TouchPhase.Ended) { //create sphere GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); //add a rigidbody Rigidbody spheresRigidBody = sphere.AddComponent(); //add mass spheresRigidBody.mass = 5; //fling sphere sphere.rigidbody.AddForce(new Vector3(0, touchLength, 0)); } } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles