Linetrace behaves weirdly on puffs and projectiles

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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.

Linetrace behaves weirdly on puffs and projectiles

Postby Jekyll Grim Payne » Wed Jan 09, 2019 5:10 pm

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

Code: Select allExpand view
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
Jekyll Grim Payne
 
Joined: 21 Jul 2008

Re: Linetrace behaves weirdly on puffs and projectiles

Postby Matt » Wed Jan 09, 2019 9:50 pm

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
Matt
Putting the XD into *xdeath since 2007
 
 
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Linetrace behaves weirdly on puffs and projectiles

Postby Jekyll Grim Payne » Thu Jan 10, 2019 2:46 am

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
Jekyll Grim Payne
 
Joined: 21 Jul 2008

Re: Linetrace behaves weirdly on puffs and projectiles

Postby Apeirogon » Thu Jan 10, 2019 3:33 am

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.
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Linetrace behaves weirdly on puffs and projectiles

Postby phantombeta » Thu Jan 10, 2019 8:42 am

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
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: phantombeta_

Re: Linetrace behaves weirdly on puffs and projectiles

Postby Jekyll Grim Payne » Sat Jan 12, 2019 6:58 am

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.
User avatar
Jekyll Grim Payne
 
Joined: 21 Jul 2008


Return to Scripting

Who is online

Users browsing this forum: gromhunter and 1 guest