- Home /
FPS controller prefab and grenade script
I have a grenade prefab, with an explosion script using this code :
var colliders : Collider[] = Physics.OverlapSphere( transform.position, explosionRadius );
for( var hit in colliders )
{
if( hit.rigidbody )
{
hit.rigidbody.AddExplosionForce( explosionPower,
transform.position, explosionRadius );
}
}
It woks well for object, but the FPS controller prefab (from Standard Asset) is not pushed back (it is a character controller), and applying a collider/rigidbody to the FPS controller doesn't work as expected.
How can I make the script working for character controller and standards object (collider + rigidbody) ?
Answer by Atnas1010 · Nov 02, 2010 at 08:27 PM
This question deals with some of the same issues
http://answers.unity3d.com/questions/25861/hitting-an-enemy-and-pushing-them-back/25881#25881
You should be able to transfer the concept to this problem.
Another way to do it would be creating an empty gameobject (with a rigidbody) at the moment of the explosion that will be affected by the force, and by script temporarily parenting your character to the empty gameobject.
Answer by Jeston 1 · Nov 02, 2010 at 08:15 PM
From what I know a character controller is Kinematic and thus doesn't react to rigid body physics. I am debating what a good course of action is myself. I am not sure how your game design is, but I can't imagine a player knocked back and still alive, so you can create a ragdoll equivalent, controll a character as a normal rigid body and self implement a character controller, or disable the character controller for the period of time you want ballistics.