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

How to stop adding torque and force when object collides with collider (or ground)

$
0
0
Hi, I use the following script to ping a coin from a monster when it dies, however, the prefab keeps spinning and moving on the floor. How can I make it stop one it has collided with something? using UnityEngine; using System.Collections; public class ScriptObjectGoldPickup : MonoBehaviour { ScriptPlayerOneManager script; public GameObject theSound; private Vector3 torque; // Use this for initialization void Start() { script = GameObject.Find("PrefabPlayerOne").GetComponent(); } void Awake() { torque.x = Random.Range (-200, 200); torque.y = Random.Range (-200, 200); torque.z = Random.Range (-200, 200); constantForce.torque = torque; rigidbody.AddForce(Vector3.up * Random.Range(2, 5), ForceMode.Impulse); } // Update is called once per frame void Update() { } private void OnCollisionEnter(Collision collision) { if (collision.gameObject.name == "PrefabPlayerOne") { script.playerInventory.playerOneGoldAmount += 1; Instantiate(theSound, transform.position, transform.rotation); Destroy(gameObject); } } } Thanks in advance for any help :)

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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