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 trialSwati Rawat
3,418 PointsCollision mask vs Contact Mask
Hi,
I am having trouble understanding the difference between the collision and contact mask. Isn't the enemy suppose to collide with the projectile instead of contact. Please help.
2 Answers
Robert Bojor
Courses Plus Student 29,439 PointsCollision - prevents objects from intersecting - default behavior when physics bodies are added
Contact - when we need to know two objects touch so we change the gameplay.
For example in a brick game, collisions are fine for physics, the ball collides with the paddle and the bricks and flies off in a different direction, and that's ok. But you need to add contact logic when the ball hits a brick so the brick disappears. You can also add logic for when the ball hits the paddle and you can play a sound.
Another example would be when you spawn multiple monsters, you turn off collisions between them ( so they can pass through each other) and check contact between monsters and create a super monster. You keep collisions between bullets and monsters and check for contact in order to damage them.
Another example would be when a spaceship passes through a laser field, there's no collision between those two but you should watch for contact so you take out shields or destroy the ship...
Just keep in mind that the collision bit mask is turned on for everything so you need to turn it off for things you want to pass through each other and the contact bit mask is off for everything and you need to turn it on for things that should react to touching each other.
Tang XiaoTing
1,253 Pointsgreat explanation, thank you
Swati Rawat
3,418 PointsSwati Rawat
3,418 Pointsthanks a lot.. understood completely.
Erion Vlada
13,496 PointsErion Vlada
13,496 PointsGreat explanation, thank you.