Quantcast
Channel: Questions in topic: "weight"
Viewing all articles
Browse latest Browse all 136

How do I add gravity to an object?

$
0
0
**Hi there, I have got my hands on a script which allows me to pick up objects and move them...** private var pickObj: Transform = null; private var hit: RaycastHit; private var dist: float; private var newPos: Vector3; function Update(){ if (Input.GetMouseButton(0)){ // if left button creates a ray from the mouse var ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (!pickObj){ // if nothing picked yet... if (Physics.Raycast(ray, hit) && hit.transform.tag == "Pick"){ // if it's a rigidbody, zero its physics velocity if (hit.rigidbody) hit.rigidbody.velocity = Vector3.zero; pickObj = hit.transform; // now there's an object picked // remember its distance from the camera dist = Vector3.Distance(pickObj.position, Camera.main.transform.position); } } else { // if object already picked... newPos = ray.GetPoint(dist); // transport the object pickObj.position = newPos; // to the mouse position } } else { // when button released free pickObj pickObj = null; } } **But I want to add gravity to the objects so that when I let go or press the button again the object drops to the floor / Ground!? Thanks -*Izzy***

Viewing all articles
Browse latest Browse all 136

Trending Articles



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