Page 1 of 1

How to prevent monster spawns from clipping into walls?

PostPosted: Wed Apr 07, 2021 11:39 am
by fcas3t
I'm the author of the Dynamic Enemy Reinforcements (DER) mod.

DER works well, overall, with only one minor bug I'm aware of. I would like to fix it, but it's a matter of engine details I know little about, so I don't even know where to start. (Full disclosure: DER is a fork of AI Director, and this is an inherited bug that Josh771 wasn't able to fix.)

The bug is that a small percentage of dynamically spawned enemies can be clipped into a wall. In the attached pk3 file, I wrote a comment block at the start of the Zscript file that explains it in detail.

It's easy to reproduce the bug, with these steps:

Spoiler: Steps to Reproduce


I realize this thread is a long shot, but I figured I might as well ask.

--------------------
edit: Good thing I asked for help! Now that it's fixed in DER_v3, I deleted the debug pk3 here. If you want to reproduce this problem in the current version, simply comment out the use of CheckMove.

Also, here's the comment block and debug settings mentioned in my original post:

Spoiler: debug code

Re: How to prevent monster spawns from clipping into walls?

PostPosted: Thu Apr 08, 2021 12:51 am
by Player701
Change line 89 of your ZScript code to the following:

Code: Select allExpand view
if ( !m.TestMobjLocation()  ||  m.height > ( m.ceilingz - m.floorz ) || !m.CheckMove(m.Pos.XY))

This adds a check to see if the spawned monster is able to move from its current position. It appears to work for me, monsters no longer spawn inside platform walls now. I'm not sure if there is a reliable way to "unstuck" them especially if you want your script to work on every map, so it's probably best to simply destroy them in this case.

Re: How to prevent monster spawns from clipping into walls?

PostPosted: Thu Apr 08, 2021 4:09 pm
by fcas3t
Thanks for figuring this out! I really appreciate you applying your expertise to this problem.

Adding CheckMove has completely fixed it in my own testing today. So I've released a new version of DER.

And, yes, I agree that it's best to destroy any clipped monster. The code already has a robust retry mechanism in place, so this is just another case of that. Full credit to Josh771 for creating this robustness in AID, which DER inherited.

(I found it funny that an actor can CheckMove its own position, so I took a quick look at the relevant GZ engine code. There's a slew of tests, one of which must detect the clipping. Very cool that there was a Zscript API for this.)