Game Development Reference
In-Depth Information
4.
From Physics 2D, add a Circle Collider 2D and a Rigidbody 2D component to it.
5.
From the Create submenu, create a new Physics 2D Material in the 2D
Assets folder.
6.
Name it Bouncy 2D .
7.
Set its Bounciness to 1 and its Friction to 0.3 .
8.
Add it to the Baby ZB's Circle Collider's Material parameter.
9.
Click Play, and watch it drop and bounce.
If you arrange it so it will hit the bundle, the bundle will get knocked out of place. So it follows that
if it is with the bundle when Is Kinematic is turned off, the bundle will suffer. Just as with regular
physics, you can exclude physics interactions by layer. Right now, all of the 3D objects are in the
Sprite layer. If you create a layer for the baby zombie bunnies and have the sprite layer ignore it, the
ground will no longer stop them. So you will have to make a layer for both.
1.
Click on the Layer drop-down menu, and select Edit Layer.
2.
Set Layer 9 to Buns and Layer 10 to Ground .
3.
Assign the Baby ZB to the Buns layer and the 2DGound to the Ground layer.
The Baby ZB will no longer be drawn by the Camera GUI, so you will have to add the new Buns
layer. The ground isn't rendered anyway, so it is good to go.
4.
Select the Camera GUI and, under Culling Mask, add the Buns layer.
The code to manage the ignore functionality is from the Physics2D class and is global, so it really
doesn't matter where it resides. The most logical object is the Game Manager, but currently it has
only the ScoreKeeper script. It is typical to create a script for general game-related code, so let's go
ahead and do that now.
5.
Create a new C# Script in the Game Scripts folder, and name it GameMisc .
Add the following to the Start function:
6.
// prevent baby zombie bunnies from colliding with bundle
Physics2D.IgnoreLayerCollision(8,9,true);
The arguments 8 and 9 are the layers involved. The collisions between objects belonging to the two
layers will be ignored if the third argument is set to true. The Boolean argument allows you to turn
the ignore on and off at will.
7.
Save the script, and add it to the Game Manager object.
8.
Click Play, and watch the action.
This time the bouncing baby zombie bunny is not able to affect the bundle.
With that little issue taken care of, you can orchestrate the drop and release of the Baby
ZB from the bundle.
 
Search WWH ::




Custom Search