x


Can't add Rigidbody component because collision prevents it

In my script, whenever I hit a trigger with the right tag, I destroy the rigidbody for the player. I want the player get his rigidbody back by pressing a button and leap away from the trigger. The problem is because the player is still colliding with the trigger, I can't add the rigidbody back. How do I add a rigidbody even when the trigger will destroy it?

more ▼

asked Jul 01 '11 at 11:43 PM

Mentalist4006 gravatar image

Mentalist4006
118 17 18 28

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You can use a boolean flag to indicate when the trigger can destroy the rigidbody - clear it when the rigidbody is destroyed, and set it when the player left the trigger:

private var canKill = true;

function OnTriggerEnter(x:Collider){

  if (canKill && x.tag == "???"){
    Destroy(rigidbody);
    canKill = false;
  }
}


function OnTriggerExit(){

  canKill = true;
}
more ▼

answered Jul 02 '11 at 12:23 AM

aldonaletto gravatar image

aldonaletto
41.5k 16 42 197

Thanks for the help!

Jul 02 '11 at 12:40 AM Mentalist4006
(comments are locked)
10|3000 characters needed characters left

set the layers on the collider of this object to ignore the triggers layer so it will not destroy it right away again, fire it out and then change the layer back

more ▼

answered Jul 02 '11 at 12:13 AM

Dreamora gravatar image

Dreamora
3.2k 1 4 25

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3339
x2504
x1797
x1705
x986

asked: Jul 01 '11 at 11:43 PM

Seen: 994 times

Last Updated: Jul 02 '11 at 12:40 AM