FPS Controller and Explosion?

I’m using the detonator framework and have an fps controller that can’t be affected by the explosion. I have written this script so far so that the player can be moved:

var targetObj : Transform;
var prefabContainer:Transform;
var proximity : float = 8;

function Update() {

    var dist = Vector3.Distance(targetObj.transform.position, transform.position);
  if (dist < proximity) {
    var instanceContain = Instantiate(prefabContainer, targetObj.transform.position, targetObj.transform.rotation);
    targetObj.transform.parent = instanceContain;
    
    }
 }

But unity doesn’t allow prefab objects to be parented. How do I set targetObj to be a specific item in the hierarchy and not a prefab?

Hai
found your problem

use

targetObj.transform.parent = instanceContain.transform;

Hi,
sorry for the late reply I was quite busy
You can
1.Create a empty gameobject and child the player obj.Remove Charactercontroller .Add rigidbody ,Use rigidbody.velocity instead of CharacterController.Move to move the player

OR

2.I havent tried this yet Add this to your player prefab

var exppos:Vector3;
var self:Transform;
var explode:boolean = false;
var minexp:float = 5.0;
var char:CharacterController;
var expspeed:float = 12;

function Explosion(pos:Vector3){
self = pos;
explode = true;
}

function update(){
if(explode){
if(Vector3.Distance(self.position,exppos) < minexp){//checking second time that if player's pos is less than minimu explosion distance
var direction = self.position - exppos;

char.Move(direction.normalized * expspeed * Time.deltaTime);

}else{explode = false;}
}
// your movement code
}

In your explosion script add this

   var pos:Vector3;

function Update(){
    var objs:Collider[] = 
 
    Physics.OverlapSphere(transform.position,9);
    
    for(var:exp in objs){
    if(exp.transform.tag =="Player"){
    exp.transform.SendMessage("Explosion",pos,SendMessageOption.DontRequireReceiver)
    ;}
    }
    }

Rate it if you like it