Game Development Reference
In-Depth Information
Finally, we will click on the
Rockslide
game object and set its
Transform
as follows:
F
Transform:
Position
:
X: 1069
Y: 32.5
Z: 677
Rotation
:
X: 0
Y: 140
Z: 0
Scale
:
X: 1
Y: 1
Z: 1
Now, we are finished, let's click
Play
to see our result. We will see that if we are entering the
TriggerArea
the rock will start falling down.
We can also click on
TriggerArea
and watch our
character walk into it from the
Scene
view.
Objective Complete - Mini Debriefing
We have created another destrucible object, which will fall down when the player gets close
to it by creaing the trigger area that will be triggered when the player has entered the area.
We also created the new
TriggerArea
script that was used to detect the player as well as
the
Rocks
script to enable
rigidbody
and make the object destrucible.
Classified Intel
In this step, we have used the
rigidbody.isKinematic = true
to disable our
rigidbody
and enable the
rigidbody
by seing it to
false
. This is the trick that we can
use to check whether our object reacted with the physics or not. We can also adapt this
trick when we want to play animaion of this object that has the
rigidbody
atached to it
by seing the
rigidbody.isKinematic
to
true
—to play the animaion and disable the
physics movement—or seing the
rigidbody.isKinematic
to
false
—to disable the
animaion and enable the physics movement.
Game over-Wrapping it up
In this chapter, we have opimized the
AIController.js
by changing from the
Physics.
CapsuleCast
to
Physics.Raycast
to increase the FPS in our game. Then, we learned
how to create the ragdoll object and apply it to the character when it is dead by using
Instatiate()
and
Destroy()
funcions to clone the ragdoll prefab and replace the old
object.
Then, we created the destrucible
Wall
and destroyed it when we shot at it by adding some
script to the
rocket
script.