[ZScript]Line3d - for debugging and more

Post your example zscripts/ACS scripts/etc here.
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

[ZScript]Line3d - for debugging and more

Post by Sir Robin »

This is something I started as a debug tool but then had some fun with it and thought I'd share it here.

I was debugging some movement code, things weren't going where I thought they should. I wished I had a way to mark points in space so I could see if my vector locations were correct. Then I wished I could draw a line from one vector to another. So I wrote a class to do that, super easy:
Line3d.SpawnTo((x1, y1, z1),(x2, y2, z2));
I didn't want to have to track and deleted the lines, so I gave them a self-destruct feature, specified in tics:
Line3d.SpawnTo((x1, y1, z1), (x2, y2, z2), 175);
And sometimes I wanted an animation to show me the flow from one end to the other, animation specified in tics:
Line3d.SpawnTo((x1, y1, z1), (x2, y2, z2), 175, 20);

But then things got a little crazy. Imagine this: You're a huge Doom nerd (duh!) and you're on your way to the birthday party of your favorite Doom demon when you realize that you were supposed to bring the decorations but you totally space-marined out. What are you going to do? No problem, I got you covered:
Give yourself a LineDrawer, select it in inventory, then go use it on a wall. Then use it on another wall, or a floor, or a ceiling, or an actor. Or even in the open air. What ever, it's a party! Go nuts!

Imagine this: The party is banging and you're feeling a bit crazy. What are you going to do? I got you covered there, too.
Give yourself LinesComingOutMyButt and go frolic. It's a party! Enjoy!

download it here

Or see the code here:
Spoiler:
Last edited by Sir Robin on Sat Oct 28, 2023 6:36 am, edited 1 time in total.
User avatar
Nash
 
 
Posts: 17449
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: [ZScript]Line3d - for debugging and more

Post by Nash »

Line trace debugging has always been annoying without any visual aid. Thank you for this.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: [ZScript]Line3d - for debugging and more

Post by Sir Robin »

Nash wrote: Fri Oct 27, 2023 2:09 pm Line trace debugging has always been annoying without any visual aid. Thank you for this.
You're welcome! I hope it's useful.

Yes I was absolutely using it to debug my use3d line tracing:

The purple line is the linetrace, the red marks are the hitbox hits, and I made the switch box transparent so I could see better whats happening from all sides.

I designed and tested these lines with pretty small lengths in mind. If you're doing full linetraces (like 2048 length) you'll need to bump up the render radius so that they get drawn.
I've never mesed with that before, looks like renderradius is readonly and there's no setter function for it so it's hardcoded after the defaults.
But according to the wiki, if radius is bigger than renderradius then that's used instead.
So add this to line3d.setEndPoints:
A_SetSize(max(abs(deltaVector.x),abs(deltaVector.y)) / 2, abs(deltaVector.z) / 2);
obvioulsy, after deltaVector has been set.
I'll edit the code in the first post. I'm also adding a fader to the animation when the line self-destructs.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: [ZScript]Line3d - for debugging and more

Post by Sir Robin »

Nash wrote: Fri Oct 27, 2023 2:09 pm Line trace debugging has always been annoying without any visual aid. Thank you for this.
I just dropped a new package with the function line3d.LineTraceVisual(), it wraps actor.linetrace() and adds the visualization. Doesn't work through portals though.
And here's a sample object to test it with:

Code: Select all

class LineTraceDebug : inventory //linetrace debugger
{
	default
	{
		+Inventory.InvBar;
	}
	states
	{
		spawn:
			UNKN A -1;
			stop;
	}
	override bool use(bool pickup)
	{
		if (!owner || !owner.player || !owner.player.mo) return false;
		FLineTraceData fltd;
		line3d.LineTraceVisual
		(
			owner, //source actor
			 //----------the usual line trace data here ...
			owner.angle,
			2048,
			owner.pitch,
			0,
			owner.height * 0.5 - owner.floorclip + owner.player.mo.AttackZOffset*owner.player.crouchFactor,
			0,
			0,
			fltd,
			//----------end of the usual line trace data
			"line3d",//which line3d subclass to use for the visual
			175, //time to live in tics
			0, //animation cycle in tics
			"Marker3d" //marker to use at the far end
		);
		switch (fltd.HitType)
		{
			case TRACE_HitNone: console.printf("Hit nothing"); break;
			case TRACE_HitFloor: console.printf("Hit floor "..fltd.HitTexture); break;
			case TRACE_HitWall: console.printf("Hit wall "..fltd.HitTexture); break;
			case TRACE_HitCeiling: console.printf("Hit ceiling "..fltd.HitTexture); break;
			case TRACE_HitActor: console.printf("Hit actor "..fltd.HitActor.GetCharacterName()); break;
		}
		return false;
	}
}
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: [ZScript]Line3d - for debugging and more

Post by Sir Robin »

Update:
Previously I had line3d.LineTraceVisual() that you could call in place of actor.linetrace(). It was a wrapper that would call the linetrace and then do the visualization. But what if you want to do the linetrace and then conditionally decide if you want it visualized? There is now line3d.VisualizeLinetrace() that takes an FLineTrace data structure and visualizes it. So for example your weapon or tool code could look like this:

Code: Select all

FLineTraceData fltd;
bool HitSomething = owner.LineTrace(owner.angle,range,owner.pitch,flags,offz,offx,offy,fltd);
//am I interested in visualizing this line? If so, for example:
if (debugmode) line3d.VisualizeLineTrace(fltd, TimeToLive: 35);
And line3d.LineTraceVisual() still functions as before, this method just gives you more control

And meanwhile I'm just over here bouncing line visualizers all over the place:

Return to “Script Library”