Advertisement
inkoalawetrust

Basic actor line of sight check for GZDoom.

Jan 19th, 2023
1,348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | Gaming | 0 0
  1. //This is written for ZScript https://zdoom.org/wiki/ZScript
  2.  
  3. Class SightBlockChecker : LineTracer
  4. {
  5.     Bool BadLOF; //If true, there is something standing in the actors' line of fire.
  6.     Actor Shooter; //The actor firing the raycast.
  7.     Override ETraceStatus TraceCallback ()
  8.     {
  9.         Actor Mobj = Results.HitActor;
  10.        
  11.         //If the trace hit an actor that isn't the shooter, and has the specified token.
  12.         //This would be better implemented with a custom flag on your actor instead of a token, but a token also allows this to work more universally, as stupid as it is.
  13.         If (Results.HitType == Trace_HitActor && Mobj != Shooter && Mobj.FindInventory ("SightBlockToken",True))
  14.         {
  15.             BadLOF = True;
  16.             Return Trace_Stop;
  17.         }
  18.        
  19.         Return Trace_Skip;
  20.     }
  21. }
  22.  
  23. //Height offset is the height relative to the callers' position that the trace will be shot from.
  24. //Range is how far the trace will go before it stops.
  25. Bool A_CheckSightBlockers (Double HeightOffset = 32, Double Range = MaxTargetRange)
  26. {
  27.     Let Check = New ("SightBlockChecker");
  28.    
  29.     Vector3 Direction = (AngleToVector(Angle, Cos(Pitch)), -Sin(Pitch)); //Fire the ray at wherever the actor is facing.
  30.    
  31.     Check.Shooter = Self;
  32.     Check.Trace ((Pos.X,Pos.Y,Pos.Z+HeightOffset),CurSector,Direction,MaxTargetRange,0);
  33.    
  34.     If (Check.BadLOF)
  35.     {
  36.         Check.Destroy();
  37.         Return False;
  38.     }
  39.     Check.Destroy();
  40.     Return True;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement