How to prevent monster spawns from clipping into walls?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)

How to prevent monster spawns from clipping into walls?

Postby fcas3t » Wed Apr 07, 2021 11:39 am

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
Last edited by fcas3t on Thu Apr 08, 2021 4:20 pm, edited 1 time in total.
Joined: 29 Nov 2020

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

Postby Player701 » Thu Apr 08, 2021 12:51 am

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.
User avatar
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

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

Postby fcas3t » Thu Apr 08, 2021 4:09 pm

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.)
Joined: 29 Nov 2020

Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests