I have a couple enemies in my game who stop moving if certain conditions are met (i.e. a projectile-based enemy will stop within a certain range from the player to stop and fire at them). On creation I attach them to the physics system using something like this.physics.add.overlap(enemy, weapon, callback).
However, I’ve noticed that when enemies stop moving (their velocities are set to 0), the overlap colliders stop firing for some reason. So they’ll avoid taking damage anytime they stop moving.
Is there a way to get the overlap to keep being detected even when entities are stationary?
Not quite the solution I was looking for, but I just rolled out my own overlap check function whenever I want to check for damage and it works.
// Checks and returns if the two sprites objects overlap each other.
function checkOverlap(obj1, obj2)
{
let intersect = Phaser.Geom.Rectangle.Intersection(obj1.getBounds(), obj2.getBounds());
return !(intersect.width === 0 && intersect.height === 0);
}
Actually I posted this after struggling for several hours to solve the problem. If I cannot find any relevant solutions online, I post a question. I have just been lucky enough to figure out the past couple problems before someone else has answered. It’s not productive to just sit around and wait for someone else after posting a question when I can just keep trying to solve on my own.
Not that it should really matter I think. Someone else in the future might ask a similar question as me and will appreciate finding an answer to their question regardless of who posted it.