What difference between collisions and contacts?
And if I have a lot of monsters, which shouldn’t interact and a hero, which should interact with monsters - what the best way to do it?
I use cocos2d-x v3.2 and build-in physical engine.
Collision are happening, when two bodies/shapes touch/overlap. It’s the event itself.
A collision can have multiple contact points. The points, where bodies/shapes are touching/overlapping each other.
You would need collision masks to filter different collisions: monster/hero, hero/monster, monster/monster.
Are the monsters dynamic bodies or static bodes?
The monsters should not interact with what? The hero? Monsters? Environment?
If you set your Hero’s category to 1
And you set your monsters’ category to 2
This tells the physics engine the two types are different.
now set the mask of the Hero to 3 - (in binary that’s 11) which tells it to collide with anything that is a 1 or a 2 (you might want to make it 2 so he only collides with monsters)
Set the mask of the monsters to 1 - which mean they only collide with the Hero.
now heros collide with monsters and monsters collide with hereos
I normally handle the collisions from the Monster point of view - that is I handle the collision events in the Monster object - and ‘tell’ the player he’s dead, rather than the other way around - but that’s just personal preference.
I thought that I do something wrong, but I read your comments and understood that did as you wrote.
I had a problem with FPS. When a lot of monsters (more than 50) pursued the hero and overlap each other FPS was falling (see attached image). I solved a problem - I changed phisics body from Box to Circle, and now FPS keeps steadily with more than 150 monsters.
But this solution may be not the best…
Circles collisions are a little faster to calculate than boxes, but that depends on the algorithms used. Chipmunk implements different algorithms than box2d. It also does not support sleeping like box2d does. Chipmunk only supports sleeping thresholds, wile box2d supports explicit sleeping of bodies.