Pushable items

I have a layer with items that the player will be able to push and move around. That works fine. The problem is when the player push a pushable item towards an non-pushable, then the non-pushable item moves. How to I prevent that from happen?

Hi galen,

sadly you didn’t give any implementation details, so I’m taking a wild guess here and assume that you just use rigidbodies and rely on the physics engine to do the rest. If so, don’t add rigidbodies to objects that are static and not supposed to be pushed around.

I see, but I want explosions to move things around and therefore I think I need a rigidbody on the items.

Okay, that’s a bit of a problem. I’m not a physics guru so please forgive me if my solution is not very elegant:
Use a rigidbody, but set isKinematic to true. When you use Physics.OverlapSphere to detect objects in the vicinity of an explosion, you could set isKinematic of unpushable objects to false before applying the explosion force. Then, in the update method of the unpushable object wait until the rigidbody isSleeping (=stopped moving) again and set isKinematic to true.

I’m pretty sure I already experienced such behaviour in AAA games because I could kick an object around right after an explosion that was static before and after I stopped touching it.

Now I know how to make it. Thanks.

This script did it. Thanks again, newbrand.

//turn kinematic to false so the explosion can move things around

function ApplyDamage (damage : float) {
rigidbody.isKinematic = false;
}

//turn kinematic back on when things stops moving
function Update (){
if (rigidbody.IsSleeping()){
rigidbody.isKinematic = true;
}
}

@script RequireComponent (Rigidbody)