[ZScript] Actor Collision Exclusion

Moderator: GZDoom Developers

User avatar
Major Cooke
Posts: 8176
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript] Actor Collision Exclusion

Post by Major Cooke »

That sounds reasonable, I do agree. I was going to ask if perhaps functionality for comparisons could be called/checked (i.e. AddFunction/Comparison() ), but I can basically see that as being almost on par with overriding PIT_CheckThing itself. On one hand, that would be quite nice where PIT_CheckThing is a virtual, yet that would probably be a total pain in the ass to deal with.

Even if that doesn't work, I suggest expanding CanCollide with two more bools:
  • ActorBlocking - Signifies the actor blocks the caller or not.
  • AmBlocking - SIgnifies the caller blocks the actor.
Or something like that.

I have a few cases where I'd like an actor to pass through another, yet the other cannot pass and gets stuck intentionally. A flag to allow this behavior might be needed. +NOUNSTICKING perhaps?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49073
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Actor Collision Exclusion

Post by Graf Zahl »

If they block, they alway mutually block each other.
The callback gets called on both actors, the currently moving one with passive set to false, and the other one with passive set to true. And if one of those two callbacks returns 'false', no collision will take place.

As for virtually overriding PIT_CheckThing, that's out of the question. Like I said, it's one of the most performance critical functions in the engine. It's better to do the checks to exclude all definitely non-colliding actors before the script gets a chance at checking the rest.
User avatar
Major Cooke
Posts: 8176
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript] Actor Collision Exclusion

Post by Major Cooke »

Alright, fair enough. I'm down for this idea!
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49073
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Actor Collision Exclusion

Post by Graf Zahl »

Added the virtual method. I tried to restrict the virtual call as much as possible but here's the catch: It has to be done rather early in PIT_CheckThing, so by allowing an exclusion a few special cases may not work 100% like without it, for example allowing non-solid things to move pushable ones. This is because I restricted the call to cases which need further handling, but not for things where a monster steps over a corpse, but a few badly handled things might fall through the cracks.
User avatar
Major Cooke
Posts: 8176
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript] Actor Collision Exclusion

Post by Major Cooke »

So basically we need to be thorough about what we're checking? If so, that's actually just what I need.
How would I use this for multiple actors? Like, do I use an Actor array or do I use multiple overrides?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49073
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Actor Collision Exclusion

Post by Graf Zahl »

Depends on the situation. I can't give you generic advice because this is a programming issue now, not one of data maintenance.
User avatar
Major Cooke
Posts: 8176
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript] Actor Collision Exclusion

Post by Major Cooke »

Okay let me rephrase: Was this designed so we would do this if we need multiple actors?

Code: Select all

override bool CanCollideWith(actor1);
override bool CanCollideWith(actor2);
Or something else?
Last edited by Major Cooke on Sun Dec 04, 2016 4:47 am, edited 2 times in total.
Edward-san
Posts: 1774
Joined: Sat Oct 17, 2009 9:40 am

Re: [ZScript] Actor Collision Exclusion

Post by Edward-san »

Uh? Multiple actors require multiple parameters, one is not sufficient?
User avatar
Major Cooke
Posts: 8176
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript] Actor Collision Exclusion

Post by Major Cooke »

Thinking about this, I'm almost wondering if the actor part is even needed for certain, when inside the virtual we could specify things like

Code: Select all

override bool CanCollideWith()
{
    if (mobj.CheckClass("actor1"))
        return false;

    if (mobj.CheckClass("actor2"))
        return true;

    super.CanCollideWith();
}
Or something like that. I'm not even sure if that's possible but...
Last edited by Major Cooke on Sun Dec 04, 2016 4:49 am, edited 1 time in total.
Edward-san
Posts: 1774
Joined: Sat Oct 17, 2009 9:40 am

Re: [ZScript] Actor Collision Exclusion

Post by Edward-san »

Sounds correct, though I wonder if isn't there something which generates a faster code on this kind of check...
User avatar
Major Cooke
Posts: 8176
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript] Actor Collision Exclusion

Post by Major Cooke »

At this point I'm just lost. :|
Edward-san
Posts: 1774
Joined: Sat Oct 17, 2009 9:40 am

Re: [ZScript] Actor Collision Exclusion

Post by Edward-san »

Uh, now I read it better and it's wrong.

You meant like this:

Code: Select all

    override bool CanCollideWith(Actor mobj, bool passive)
    {
        if (mobj.CheckClass("actor1"))
            return false;

        if (mobj.CheckClass("actor2"))
            return true;

        super.CanCollideWith(mobj, passive);
    }
User avatar
Major Cooke
Posts: 8176
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript] Actor Collision Exclusion

Post by Major Cooke »

But that's my biggest issue. The thing is, you don't know what mobj is supposed to be. I'm talking about grabbing the actor that may potentially be blocking and passing it through. How can you even tell if it's the correct actor or not?
User avatar
Major Cooke
Posts: 8176
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript] Actor Collision Exclusion

Post by Major Cooke »

...Okay, better question. Graf, how did you test this to ensure the multi-actor thing works?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49073
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Actor Collision Exclusion

Post by Graf Zahl »

Major Cooke wrote:

Code: Select all

override bool CanCollideWith()
{
    if (mobj.CheckClass("actor1"))
        return false;

    if (mobj.CheckClass("actor2"))
        return true;

    super.CanCollideWith();
}
I wouldn't use CheckClass.

Either use 'GetClass() ==' if you want to check a single class or 'mobj is "classname"' if you want to check for a group of actors, you can of course also do 'GetSpecies() == 'speciesname', or check friendliness or check if one actor has a specific damage type or whatever else you like to have tested. Calling the super method is not needed, AActor' just returns true and does nothing.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”