Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //BUG: Sometimes this function will return true for a position that is over a tall ledge (e.g a bridge).
- //Checks if the straight line between the callers' position and the specified position can be walked up to.
- //TargetPos: The position to check if it's walkable.
- /*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,
- 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 !*/
- Bool IsPosReachable (Vector3 TargetPos, Double DistCutoff = 0)
- {
- Vector3 OldPos = Pos;
- Bool Interp = bDontInterpolate;
- Vector2 Path = Level.Vec2Diff( Pos.XY, TargetPos.XY );
- Double Distance = Path.Length()-DistCutoff;
- Double Spacing = Radius*2;
- If (Distance <= 1) Return False;
- Path /= Distance;
- bDontInterpolate = True; //No movement interpolation during the test.
- For (Int I = 0; I < Distance; I += Spacing)
- {
- If (Level.Vec2Diff (Pos.XY, OldPos.XY).Length() >= Distance) Break; //The check went further than the distance to the target position. Success
- 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
- //Run as many times as it takes between you and your destination.
- FCheckPosition Data;
- If (TryMove (Level.Vec2Offset(OldPos.XY, Path*I), 1, tm:Data))
- {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.
- //If one of them fails, then return false.
- Else
- {//a_log ("i can't head here");
- bDontInterpolate = Interp;
- SetOrigin (OldPos,False);
- Return False;
- }
- }//a_log ("valid path");
- bDontInterpolate = Interp;
- SetOrigin (OldPos,False);
- Return True; //No TryMove call returned false.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement