Game Development Reference
In-Depth Information
Objective Complete - Mini Debriefing
We just created the ragdoll prefab game object to replace the AI when the AI is dead, which
will make it look realisic. We also have used GameObject.Destroy() to destroy the AI
game object in the scene and use the Instantiate() funcion to clone the ragdoll prefab
to replace the AI game object that has already been destroyed.
Classified Intel
In this secion, we created the ragdoll object to replace our Enemy when it dies, which looks
good. However, we will see that robot_AI_ragdoll just fell down to the ground without
any force from the rocket that was fired at it.
To make it much more fun and realisic, we can do this using two diferent equaions.
First, we can add force (using the AddForce() funcion) to our ragdoll's rigidbody , which
will make our ragdoll move following the rocket direcion. We can do this by adding a script
in the OnCollisionEnter(collision : Collision) in the AIController script, as
highlighted in the following 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);
var obj_aiPrefab : GameObject = Instantiate(aiRagdoll,
transform.position, transform.rotation);
 
Search WWH ::




Custom Search