Can we rotateWithCollisions?

Picture a swinging door… It has checkCollisions, but that doesn’t apply to rotations, so it will close right through the player. Is there a way to enforce collisions while rotating?

I’m thinking of the physics engine, but I’m not currently using physics, so that’s a big change.

Hello @alekop , how are you doing?

Maybe you can place an invisible square on the are that the swinging door moves and use collision check against the player mesh. This way you check if it is safe or not to close the door without having to use physics.

If that does not work, can you provide a Playground example so we can discuss more ideas?

1 Like

Hi @srzerbetto,

Thanks for the suggestion. That’s a good solution for most cases. Here’s a starting-point playground: https://playground.babylonjs.com/#Z1SZWA#1. It doesn’t have any collision avoidance features at the moment, but I’ll add some.

I’m thinking of using collision groups to make this “safe area” around the door solid for NPCs, so they don’t wander in its way.

The only remaining issue is moving the player away from the door if it swings toward them. This would require some protocol between door and player, where the door tells the player its minimum safe distance, and the player backs off if needed. Or just make doors always open away from the player, and have “safe areas” on both sides.

Now that I think about it more, this is not a collision detection issue at all. I mean, we shouldn’t collide with swinging doors at all.

UPDATE: Here’s an updated playground, with door avoidance: https://playground.babylonjs.com/#Z1SZWA#7. The door defines some “safe positions” (one for each side). If you stand there, you won’t get hit by the door, and you don’t need collision detection or mesh intersection. The toggleDoor function figures out which side the player is closest to, and moves the player to that position, then opens/closes the door. This also takes care of the scenario where the player tries to close the door while standing in the doorway.

1 Like