Hello, I have a rocket prefab with a rigidbody and box collider that needs to collect coins (fuel) in order to keep moving up. I would like the rocket to stop moving up (run out of fuel) if you stop collections coins and fall to the ground. My current code after hitting a box trigger is this.
function OnTriggerEnter(fuel: Collider){
if(fuel.gameObject.tag == "fuel"){
Debug.Log("We hit a fuel box!");
constantForce.force = Vector3.up * 50;
}
}
I am not sure how to disable the constant Force code above or make it dissipate over time. So I used a force function
rigidbody.AddForce (0, 10, 0);
This only launched me up into the air exponentially for a brief time but at least I ended up crashing back into the ground.
Any help would be appreciated.
Thanks!
↧