[SOLVED]Check if Specific Actor is in Front of Another

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!)
Post Reply
Kan3x
Posts: 52
Joined: Tue Nov 08, 2022 4:19 pm

[SOLVED]Check if Specific Actor is in Front of Another

Post by Kan3x »

Hi.

Like the title says, I have a monster that should check if a specific actor is in front of him, between the monster itself and the target basically, and if it returns true it should do stuff , but I cannot make it work.

I have this actor:
Spoiler:
Which get spawned by a spawner actor, which is spawned by the actual monster (I had to set up a master/child relation between these and transferred the pointers to the "ShieldPart" actor for another thing).

Then, in the monster "see" state I added this to check if there's something in front of him:
Spoiler:
But it never gets to the "still" state ("shield" is a variable directly connected to the ShieldParts that are "alive" and when the shield is activated it is = to 32).
The spawner spawns 32 ShieldParts on a plane and the hitboxes of every single ShieldPart are overlapping, so there are no "holes" that the monster can see through.

What am I missing???
Last edited by Kan3x on Fri Nov 11, 2022 9:36 am, edited 1 time in total.
User avatar
Player701
 
 
Posts: 1640
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Check if Specific Actor is in Front of Another

Post by Player701 »

You may want to add the following flags to A_CheckLOF:
  • CLOFF_ALLOWNULL - jumps even if there is no target (provided that you're actually anticipating such a scenario);
  • CLOFF_CHECKPARTIAL - performs the check even if the target is out of range (this is likely what's causing the problem - otherwise, if the target is too far away, the trace is cancelled entirely).
Also try to adjust the height offset (currently 64). The height of your ShieldPart actor is 32; if they are spawned on the floor, then an offset of 64 is definitely too high.

And since you're not using the result of A_CheckLOF to jump, you can also replace it with just CheckLOF, which has all the same parameters except the first one (the state to jump to).

Note that this whole thing looks somewhat like a hack; it should have probably been done with a LineTracer instead. But still, it should work if you do not have any other +GHOST actors in your mod (and do not want compatibility with mods that do) - I just tested your code in-game, and it did work after applying the adjustments described above.
Kan3x
Posts: 52
Joined: Tue Nov 08, 2022 4:19 pm

Re: Check if Specific Actor is in Front of Another

Post by Kan3x »

Player701 wrote: Fri Nov 11, 2022 12:25 am You may want to add the following flags to A_CheckLOF:
  • CLOFF_ALLOWNULL - jumps even if there is no target (provided that you're actually anticipating such a scenario);
  • CLOFF_CHECKPARTIAL - performs the check even if the target is out of range (this is likely what's causing the problem - otherwise, if the target is too far away, the trace is cancelled entirely).
Also try to adjust the height offset (currently 64). The height of your ShieldPart actor is 32; if they are spawned on the floor, then an offset of 64 is definitely too high.

And since you're not using the result of A_CheckLOF to jump, you can also replace it with just CheckLOF, which has all the same parameters except the first one (the state to jump to).

Note that this whole thing looks somewhat like a hack; it should have probably been done with a LineTracer instead. But still, it should work if you do not have any other +GHOST actors in your mod (and do not want compatibility with mods that do) - I just tested your code in-game, and it did work after applying the adjustments described above.
I guess I didn't accurately understood what those flags do, dumb me, now it works perfectly thank you!

I see, I didn't know about the existence of LineTracer (I just read how it works, even I haven't found much, but it seems that I would need a "better" set up to use that, so for now I'll stick with the little hacky way).
About the GHOST thing, I basically only used it cause I wanted that only the projectiles of my monster must be able to pass through the shield and it should've been a temporary solution. I'll remove that and go for ThruBits property, cause you're right, I have no other GHOST actors, but others that will use my mod might have them.

About this: I know that I have to set the ALLOWTHRUBITS flag and give (in this case) the shield actor a value for the ThruBits property, but how do I set the same "group" on the projectiles I want? Do I just need to add the ThruBits property on them too with the same value?
User avatar
Player701
 
 
Posts: 1640
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Check if Specific Actor is in Front of Another

Post by Player701 »

Kan3x wrote: Fri Nov 11, 2022 5:19 amAbout this: I know that I have to set the ALLOWTHRUBITS flag and give (in this case) the shield actor a value for the ThruBits property, but how do I set the same "group" on the projectiles I want? Do I just need to add the ThruBits property on them too with the same value?
Haven't used ThruBits myself, but from the looks of it the answer is yes. Note that if you only have one group of actors supposed to pass through each other, the actual value is irrelevant (provided it is non-zero). Otherwise, do keep in mind that the values are compared bitwise, specifically with the bitwise AND operator "&". Actors pass through each other if the result of the operation is non-zero.
Kan3x
Posts: 52
Joined: Tue Nov 08, 2022 4:19 pm

Re: Check if Specific Actor is in Front of Another

Post by Kan3x »

Player701 wrote: Fri Nov 11, 2022 7:35 am but from the looks of it the answer is yes
Great, everything's working perfectly fine now with ThruBits, thank you again!
Post Reply

Return to “Scripting”