Linetrace behaves weirdly on puffs and projectiles

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
User avatar
Jekyll Grim Payne
 
 
Posts: 1065
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)
Contact:

Linetrace behaves weirdly on puffs and projectiles

Post by Jekyll Grim Payne »

This behavior is pretty weird and I don't know what's causing it. Here's the code:

Code: Select all

version "3.3"
 
Class PuffChecker : Actor replaces Bulletpuff
{
Default {
    +NOBLOCKMAP
    +NOGRAVITY
    -ALLOWPARTICLES
    +DONTSPLASH
    +PUFFGETSOWNER
    }
states
    {
    Spawn:
        TNT1 A 1 NoDelay {
            if (target) {
                angle = target.angle;
                pitch = target.pitch;
                }
            string hittex;
            FLineTraceData linedata;
            LineTrace(angle,radius+8,pitch,TRF_THRUACTORS|TRF_NOSKY,0,0,0,linedata);   
            if (linedata.HitType == TRACE_HitFloor)
                hittex = texman.GetName(floorpic);
            else if (linedata.HitType == TRACE_HitCeiling)
                hittex = texman.GetName(ceilingpic);
            else
                hittex = texman.GetName(linedata.HitTexture);          
            Console.PrintF("%s",hittex);
            }
        stop;
    }
}
 
Class RocketChecker : DoomImpBall replaces Rocket
{
states
    {
    Death:
        TNT1 A 0 A_SpawnItemEx("PuffChecker");
        goto super::death;
    }
}

If you try to shoot the projectile, which spawns the puff, which does the linetrace, you'll be able to receive wall texture names but not floor or ceiling texture names, i.e. linetrace will consider that it didn't hit either. If you add NOINTERACTION to the puff, linetrace will be able to hit the ceiling but still not the floor.

If you instead just fire a hitscan attack that spawns the same puff, you'll still be able to receive wall texture names, but with ceilings and floors — only sometimes.

There are also some other variables involved, but overall this behavior seems really weird to me. It looks like, to get a solid result I should make the distance of the check pitch-dependent, but I'm not sure. I'd appreciate any advice.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Linetrace behaves weirdly on puffs and projectiles

Post by Matt »

Just some wild guesses since I have this problem from time to time:

- Have you defined the actor's radius and height?

- Does it help if you set the offsetz up from the base of the actor? (LineTrace does not assume any automatic Z offset)
User avatar
Jekyll Grim Payne
 
 
Posts: 1065
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)
Contact:

Re: Linetrace behaves weirdly on puffs and projectiles

Post by Jekyll Grim Payne »

Matt wrote:Just some wild guesses since I have this problem from time to time:

- Have you defined the actor's radius and height?

- Does it help if you set the offsetz up from the base of the actor? (LineTrace does not assume any automatic Z offset)
Yes for radius and height, I just realized I posted a slightly outdated code. However, regardless of those values, to make it work for hitscans, the *distance* of linetrace has to be rather big. Again, I think it has to do something with pitch, but if I make it too big, like 256, it looks like that sometimes it'll shoot through planes — like, shooting at an angle at the ceiling close to the wall, it'll return the wall texture sometimes.

I haven't tried offsetz yet. It just hit me that I should probably run a z-height check from the puff and then simply fire linetrace directly up, or down or straight ahead instead of retaining the pitch. I'll be right back...
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Linetrace behaves weirdly on puffs and projectiles

Post by Apeirogon »

For me you code print something in console always, except for floors, and sometime walls, it print "althudcf" instead of actual texture name.

And even after I add some checks it still sometimes print "althudcf". Most times this happens when shoot in the angle between wall and sector. Probably this is a bug, because I dont find any texture with the name althudcf, except file althudcf.txt in the root of a gzdoom pack, which define the hud configuration.
User avatar
phantombeta
Posts: 2084
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Linetrace behaves weirdly on puffs and projectiles

Post by phantombeta »

Setting the OffsetZ makes it randomly show the correct result - the reason it only works randomly is because of the default behaviour of bulletpuffs having randomized Z coordinates, by the way - if you disable that in your calls to A_FireBullets, it'll probably work most of the time or all the time.

Also, there's a reason for the incorrect result with TexMan.GetName - it's likely giving you an invalid name for non-existant, invalid or null textures (which you can easily check for, by the way). This can be easily fixed by replacing that else with "else if (linedata.HitType != TRACE_HitNone)". If HitType is TRACE_HitNone (i.e. didn't hit anything), the contents of the struct will likely be garbage or all zeroes.

As for the reason why it didn't work without an OffsetZ, it's because linetraces crash the game if they go past sector floors or ceilings, through one-sided walls or through the upper or lower part of a two-sided linedef. To handle this, LineTrace likely doesn't even execute the linetrace if the Z origin for the actor is the same as the floor's or ceiling's Z. (I completely forgot about this when helping you with this issue before)
User avatar
Jekyll Grim Payne
 
 
Posts: 1065
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)
Contact:

Re: Linetrace behaves weirdly on puffs and projectiles

Post by Jekyll Grim Payne »

If anyone's interested, ultimately I added a pos.z check against floorz/ceilingz when the puff appears, then I just run linetrace at straight angles (straigh ahead or down or up) to avoid any uncertainty. May not always work perfectly at angles between planes and walls, but I can live with that.
Post Reply

Return to “Scripting”