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

Ranvir Sahota
Ranvir Sahota
9,844 Points

Where to place trigger?

In a game where you will be interactive with many different game objects like NPCS, Trees, Walls and Enemies. Why put a trigger on each of them where you can just place on the player and have the code in place. Or is the fact the code would be in place that is bad practice because it decreases readability?

1 Answer

Nick Pettit
STAFF
Nick Pettit
Treehouse Teacher

Hi Ranvir,

Anything that interacts with physics needs, at the very least, a physics collider component (such as a sphere collider, box collider, and so forth). This includes the player character and anything you expect them to collide with. If a wall or a tree doesn't have a collider, then the collider on the player character won't know if an intersection has occurred.

While it's possible to use the 3D mesh to detect collisions, this is extremely computationally expensive. It's far better to make primitive approximations (like boxes and spheres) that can be calculated quickly by the phyiscs engine. Hopefully that makes sense!