Advertisement
inkoalawetrust

IsPosReachable

Apr 16th, 2023
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.95 KB | Gaming | 0 0
  1.     //BUG: Sometimes this function will return true for a position that is over a tall ledge (e.g a bridge).
  2.     //Checks if the straight line between the callers' position and the specified position can be walked up to.
  3.     //TargetPos: The position to check if it's walkable.
  4.     /*DistCutoff: The amount of map units to trim off the distance between the callers' pos and TargetPos. Useful for subtracting the radius of another actor,
  5.     so that if you are checking if a position to another actor can be reached, the check doesn't return false because the actor itself is in the way !*/
  6.     Bool IsPosReachable (Vector3 TargetPos, Double DistCutoff = 0)
  7.     {
  8.         Vector3 OldPos = Pos;
  9.         Bool Interp = bDontInterpolate;
  10.         Vector2 Path = Level.Vec2Diff( Pos.XY, TargetPos.XY );
  11.         Double Distance = Path.Length()-DistCutoff;
  12.         Double Spacing = Radius*2;
  13.         If (Distance <= 1) Return False;
  14.         Path /= Distance;
  15.        
  16.         bDontInterpolate = True; //No movement interpolation during the test.
  17.         For (Int I = 0; I < Distance; I += Spacing)
  18.         {
  19.             If (Level.Vec2Diff (Pos.XY, OldPos.XY).Length() >= Distance) Break; //The check went further than the distance to the target position. Success
  20.             Else If (Level.Vec2Diff (Pos.XY, TargetPos.XY).Length() <= Radius*2.5) Break; //The caller is with 2.5 radii of the target position. Success
  21.             //Run as many times as it takes between you and your destination.
  22.             FCheckPosition Data;
  23.             If (TryMove (Level.Vec2Offset(OldPos.XY, Path*I), 1, tm:Data))
  24.                 {SetZ (GetZAt (Pos.X,Pos.Y,flags:GZF_ABSOLUTEPOS));/* spawn ("candlestick",pos);*/} //Update the actors' Z position. TryMove should do that internally, but it doesn't. GZDoom moment.
  25.             //If one of them fails, then return false.
  26.             Else
  27.             {//a_log ("i can't head here");
  28.                 bDontInterpolate = Interp;
  29.                 SetOrigin (OldPos,False);
  30.                 Return False;
  31.             }
  32.         }//a_log ("valid path");
  33.         bDontInterpolate = Interp;
  34.         SetOrigin (OldPos,False);
  35.         Return True; //No TryMove call returned false.
  36.     }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement