GameDev Tutorial – Basic Circle Chain Engine Using Unity3D – parts 2 and 3

I hope you enjoyed the 1st part of the Circle Chain Engine using Unity3D. Alex Cançado published the 2nd and 3rd step and I am going to group these two steps of his fantastic tutorial in this post:

Time to put some mouse interaction.

1. add the new textures: red circle, bullet red; configure texture type to advanced, uncheck generate mipmap and filter mode to point.

2. drag and drop the greencircleprefab from prefab folder to the hierarchy. drag and drop the red circle texture to this and rename to RedCircle. Remove the GreenCricle script from it. We will create a script to this object later.

3. But we still need create our Bullet prefab.

To make it simple, just duplicate the RedCircle object from hierarchy panel with Command+D or (Control+D in windows?). Then rename this new object to RedBulletPrefab.

Drag n drop the bullet texture to it. We will add a Bullet script later. All done, drag n drop the RedBulletPrefab from Hierarchy to your Prefab folder in your project files, so we create a Prefab of the bullet object.

Since we will instantiate bullet objects by code, you can delete the RedBulletPrefab from the Hierarchy panel.

4. Now lets add some player control to RedCircle: go to your script folder and create a new c# script RedCircle; Don’t forget to add this script to the RedCircle.

5. Now you can movement the Red Circle with mouse! But we still need create a script to control the bullets and then add this script to our RedBulletPrefab prefab:

6. Now it’s possible “shot” when we press the left mouse button:

You can download the project here. Open the scene in Assets > CircleChain02 > Scenes and try it!

What we need to do in this third part:

. RedBullet collides with GreenCircle.

. GreenCircle spawn GreenBullets.

. repeat the process each collision between “bullets” objects and GreenCircles.

Basically we need add physics components to GameObjects, then add colliders.

1. In the prefab folder, select RedBulletPrefab. In the Inspector panel, at bottom, click the button Add Component > Physics > Rigidbody. Then uncheck “use gravity”, check “Is kinematic” and I checked too the z position and x, y, z rotation freeze options.

2. With RedBulletPrefab selected, add a new physics component, collider. For bullets I choose Box Collider, for the Green Circle I added an Sphere Collider. Just check “Is trigger” since we will use C# script to control collisions.

3. Do the steps 1 and 2 above to GreenCirclePrefab.

4. Let’s create a new prefab, GreenBulletPrefab. It’s based in the RedBulletPrefab, so drag and drop RedBulletPrefab into Hierarchy panel. Rename to GreenBulletPrefab. Go to Texture folder and assuming that you have already imported the greenbullet.png (Texture type: advanced, uncheck generate mip maps, filter mode: point), drag and drop into the new GreenBulletPrefab. Then drag and drop GreenBulletPrefab to the Prefab objects. Now you can delete GreenBulletPrefab from Hierarchy panel, since we will instantiate this object with C# script.

5. Open the CircleChain script in the Script folder. Here we need check for collisions and spawn the green bullets, then destroy the green circle object. Basically we will add this:

We used this for our RedCircle script.

Thats it!


Download here the new complete project files: Unity Circle Chain Part 3.

Just open the “scene03” in the scene folder.

  • DQvsRA

    Thank you for that tutorial! Wait for more complex one.