Game Development Reference
In-Depth Information
5.
that has a position of the GrandEntrance game object it is attached to, minus
4 from its y coordinate value to position it on the ground centered in the
DustPuff particle system emission,
6.
and a radius of 10.
(7) for(var cldr : Collider in colliders)
This for loop will iterate through the array of colliders
7.
(8) if(cldr.rigidbody == null) continue;
8.
Check for a rigidbody attached to the collider. Remember a rigidbody is
required when using physics forces. If there is no rigidbody, continue means
do not execute the following block of code, and instead move on to the next
item in the for loop.
. (9) (10) (11)
cldr.rigidbody.AddExplosionForce(10, transform.position - Vector3(0,
(12)(13) (14)
4, 0), 10, 0, ForceMode.Impulse);
If there is a rigidbody attached, apply an AddExplosionForce
9.
10.
of force 10
11.
from the same position as the DustPuff particle system emission
12.
with an explosion radius of 10
13.
no extra upward force (use this when you want a little more upward “pop”)
using ForceMode.Impulse , which applies all of the force instantaneously
rather than over a period of time. This force decreases with distance from the
designated position and reaches zero at the designated radius.
14.
If you playtest now, nothing happens because there are no game objects within the radius of the
Physics.OverlapSphere . To see this in action, in the Project panel drill down to the Assets ➤ Sample
Assets ➤ Prototyping ➤ Prefabs ➤ Compound Prefabs folder. Drag a Smash Boxes prefab into the
Scene view, then give it a Transform.position of (-5, 0, -5) and a Transform.rotation of (0, 90, 0).
Create a duplicate of this game object by using Ģ+D in the Hierarchy, then place this duplicate
at a Transform.position of (8, 0, -5). Create a third duplicate, this time with a Transform.position of
(0, 0, -11) and a Transform.rotation of (0, 0, 0). Save the scene, save the project, and playtest.
Boom! Notice how the first Smash Boxes pile is completely blown away, while the second has its
farthest box components barely touched, and the third Smash Boxes pile isn't touched at all. This
is because of their placement relative to the explosion radius of 10 designated in the ImpactForce
script.
As far as game design and style goes, this is a pretty overdone entrance for our player, but it serves
as a great exercise for building particle effects.
 
Search WWH ::




Custom Search