phoboslab / Impact

HTML5 Game Engine
MIT License
1.99k stars 204 forks source link

Collision FIXED on both entities #61

Open rontrek opened 5 years ago

rontrek commented 5 years ago

Hi, I'm trying to implement a roaming enemy or npc entities which stops the player when collided and vice versa. How do I go about this? If I set FIXED on both player and npc, the npc still slides away when collided.

Joncom commented 5 years ago

If you want the player to get stopped by the NPC, then your player needs to be weaker than the NPC. Perhaps try leaving NPC as FIXED (the strongest), and change the player to ACTIVE (weaker, but still relatively strong). And if you have some entities you want to get pushed by the player, you could assign them LITE (even weaker yet).

rontrek commented 5 years ago

Thanks @Joncom. But I want them to cancel each other out not weaker than the other. If a player bumps the npc, the player stops, same goes with npc when bump into the player.

In short, all entities will be stopped when bumping into each other and they cannot push each other aside. I'm trying to do a top down game.

Joncom commented 5 years ago

Have you tried ACTIVE-ACTIVE or LITE-LITE?

rontrek commented 5 years ago

Yes, the results:

ACTIVE-ACTIVE - still slides either entities LITE-LITE - just passes without any collision

should a FIXED-FIXED type stopped both or is this a bug?

https://impactjs.com/forums/help/fixed-vs-fixed-collision

rontrek commented 5 years ago

..also quoting the specific documentation page, it says:

The behavior for FIXED vs. FIXED collisions is undefined.

https://impactjs.com/documentation/class-reference/entity#collides

Is there a workaround?