Search Unity

Exploding Floor Tiles

Discussion in 'Scripting' started by deram_scholzara, Aug 26, 2005.

  1. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    Ok...so I have a bunch of floor tiles whose rigidbody physics I want to activate only after being within the blast radius of a grenade or other large explosive...then, if possible, I'd like to deactivate the rigidbody physics after about seconds.

    I have already built the floor and applied physics properties to the individual tiles, but I don't want them to be constantly calculating physics properties and bogging down the CPU...Currently they're either always on or always off.

    How should I go about doing this?
    Thank you very much in advance to all who contribute...and major kudos to the company that just produced the almost-perfect engine for my game.
    Thanks again.
     
  2. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    deram_scholzara likes this.
  3. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    Yes, but my problem is that these tiles, unless stopped within a certain time limit, will keep moving and thus prevent the automatic stopping from kicking in. If the stopping mechanism could be changed from a velocity test to a timed test only for specific objects, and be made to still reactivate when a force is applied, then that is what I am looking for.

    I also have the problem of overlapping collision boxes...when rigidbodies are turned on this causes the floor tiles to jump out of their places on the floor...so if the rigidbody script could be activated only when the tiles have been impacted by a blast greater than or equal to a certain damage level and then deactivated after ten seconds (and still be reactivatable by a similar blast), that would be perfect.

    Attached is a shot of the floor.
     

    Attached Files:

  4. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    I don't know of any direct method of deactivating only the rigidbody component of a gameObject. So, other possibliies are:

    1. Create the tiles without rigidbodies, then, when you need the blast, add the rigidbody component ( gameObject.AddComponent("RigidBody")). I don't know how to remove the rigidbody component once you have created it though

    2. If you need to repeatedly "activate" and "deactivae" the rigidbody then one way is to have two identical gameObjects for each tile, one with a rigidbody and the other without and then swich their gameObject activation states around after transfering their position/rotation info - haven't tried it myself so not sure how well it would work.

    Cheers,
    Richard.
     
    deram_scholzara likes this.
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    use the isKinematic flag in the rigid body.
     
    deram_scholzara likes this.