Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development How to Make a Video Game Pickups Script the Fly Pickup

Mike Atkinson
Mike Atkinson
6,882 Points

Could you put a trigger collider on the geometry of the fly?

Just putting my thinking out there.

Could you put the collider on the body of the fly, instead of the larger parent object? Would it really make much difference to the game play?

if you did, would it be better to use a sphere collider? or a mesh? How much would this impact performance?

I suppose it is easier on the fly object, if you had the collider on any of the children, you would need to make sure to reference the highest parent (fly) to Destry().

Mike Atkinson
Mike Atkinson
6,882 Points

Great! I put put a small sphere collider on the Geometry object, set it to Trigger, and added the following script:

public class testScript : MonoBehaviour {
    void OnTriggerEnter (Collider other) {
        if (other.CompareTag ("Player")) {
            GameObject rootParent = gameObject.transform.parent.gameObject;
            Destroy (rootParent);
        }
    }
}

The player only Destroys the fly if it touches (very close) the actually visual fly geometry. If you increase the X value of the Geometry's Position, your frog can even move around inside the circle drawn by the fly!