Game Development Reference
In-Depth Information
/* Make the ragdoll react to the rocket force*/
var f_force : float = 1000;
//Get transform direction of the rocket
var v3_rocketDir : Vector3 = rocket.transform.
TransformDirection(Vector3.forward);
//Get the rigid body of gun and the ragdoll
var a_rigid : Rigidbody[] = obj_aiPrefab.GetComponentsInChil
dren.<Rigidbody>();
//Apply force to the gun rigidbody and ragdoll
for (var r : Rigidbody in a_rigid) {
r.AddForce(v3_rocketDir * f_force);
}
GameObject.Destroy(transform.parent.gameObject);
}
}
}
The second is using the explosive force (using the AddExplosionForce() funcion),
which will make our ragdoll move in a diferent direcion depending on the distance from
the explosive posiion to our ragdoll's rigidbody object. We can do this by replacing the
following script in the same funcion as in the preceding code:
//Checking for the collision if the rocket hit the AI
public function OnCollisionEnter(collision : Collision) : void {
if (collision.transform.tag == "Rocket") {
var rocket : Rocket = collision.gameObject.GetComponent(Rocket);
var f_damage : float = rocket.getDamage();
aiHP -= f_damage;
b_isGotHit = true;
if (aiHP <= 0) {
aiHP = 0;
var obj_aiPrefab : GameObject = Instantiate(aiRagdoll,
transform.position, transform.rotation);
/* Make the ragdoll react to the explosion force*/
var f_force : float = 1000;
//Get the rigid body of gun and the ragdoll
var a_rigid : Rigidbody[] = obj_aiPrefab.GetComponentsInChil
dren.<Rigidbody>();
//Apply force to the gun rigidbody and ragdoll
for (var r : Rigidbody in a_rigid) {
r.AddExplosionForce(f_force, rocket .transform.position,
100.0);
}
GameObject.Destroy(transform.parent.gameObject);
}
}
}
 
Search WWH ::




Custom Search