CanCrossLine virtual

Moderator: GZDoom Developers

User avatar
Major Cooke
Posts: 8059
Joined: Sun Jan 28, 2007 3:55 pm

CanCrossLine virtual

Post by Major Cooke »

Pull Request

Pretty simple virtual. Since there's no way to really tell if an actor can cross certain lines, I had to come up with this for the sake of not needing to recreate A_Chase by hand.
Returning false means the line is blocking. Side is the side of the line the actor is on, currently, at the time of calling.

This function occurs after most PIT_CheckLine checks, but before other sector updating code near the end, meaning it handles things like MaxStepHeight before it calls this function.

Example code here allows for monsters to cross over and out of damaging floors, since I have programmed them to take damage from damaging floors just like players do via the Tick() override.

Code: Select all

override bool CanCrossLine(Line crossing, int side)
{
	// Already in a sector that's burning the monster, and may need to
	// cross over some in order to reach ground without it, so allow it.
	if (CurSector.DamageAmount > 0)
		return true;
	
	Line l = crossing;
	
	// If walking away from the direction of the damage sector, allow
	// walking over the line. Otherwise they can get stuck.
	double ang = VectorAngle(l.delta.x, l.delta.y) + 90;
	double delta = AbsAngle(ang, angle);
	
	if (l.frontsector.DamageAmount < 1 && delta >= 90)
		return true;
	if (l.backsector.DamageAmount < 1 && delta <= 90)
		return true;
	
	// Crossing over the front side, so check the back sector.
	if (side == Line.Front)
		return (l.backsector.DamageAmount < 1);
	
	// Vice versa.
	return (l.frontsector.DamageAmount < 1);
}
Last edited by Major Cooke on Wed Feb 23, 2022 12:34 pm, edited 1 time in total.
User avatar
Major Cooke
Posts: 8059
Joined: Sun Jan 28, 2007 3:55 pm

Re: CanCrossLine virtual

Post by Major Cooke »

I redid the submission. Hopefully its better now.

Return to “Closed Feature Suggestions”