[Spell] obstacle detection

Level 25
Joined
Mar 29, 2020
Messages
1,466
Hey,

I have a unit on a mission, and I want it to detect when a different unit (building/unit) is blocking it's path (only when completely blocked. having to walk around is ok) and destroy it so it can continue on it's mission.

the best way I thought of doing that, it by detecting when it's standing on the same point for a while when it should have been moving, and then just having it destroy the thing that is closest to directly in front of it.


is there a better way to detect what is blocking a unit's pathing in it's attempt to get to a specific item/location/unit?
 
Level 20
Joined
Jan 3, 2022
Messages
364
I don't know of a good way. There are no functions related to path finding at all.
The best workaround I thought of was to create an invisible dummy unit with very high speed, same size and pathability. Let it move from A-B (or B-A if you want to arrive at a conclusion earlier) and check if it roughly gets stuck in a spot or both dummies go past each other (met half way = ok, passable).
 
Level 25
Joined
Mar 29, 2020
Messages
1,466
I don't know of a good way. There are no functions related to path finding at all.
The best workaround I thought of was to create an invisible dummy unit with very high speed, same size and pathability. Let it move from A-B (or B-A if you want to arrive at a conclusion earlier) and check if it roughly gets stuck in a spot or both dummies go past each other (met half way = ok, passable).
the issue with that is that if it's not instantaneously checking in front of the real unit - it might not be up to date by the time the real unit reaches the point (someone could build a building in it's path after the scout dummies pass by, but before the real unit). and exceeding the speed limit causes pathing irregularities (according to DSG here), which would defeat the purpose in this case.. but it's a cool idea, thanks!
 
I think your original solution (checking if the unit has been standing in place for a while) is probably the best solution. As Luashine mentioned, we don't get insight into the unit's pathing or obstructions via code, so your best bet is trying to detect when they get "stuck" and hoping it is because of a unit that is around them.

I'm guessing the concept for this system is to prevent people from surrounding the unit, which would mess up the mission.

At a high-level, if I were designing a system around this--I'd try to take it one order at a time. Conceptually, you probably want the unit to be always making progress on a given order (e.g. move to some point X). So you'll need to "track" the unit over time (e.g. with a timer). To detect if the unit gets "stuck", I would check if the distance between the unit's current position and their last position is less than some small number (e.g. 5), and if so, increment a variable. If that variable crosses a threshold, e.g. 2 seconds of being stuck, then you'll trigger the logic to kill something in front of it. You can read this thread for an example on how to get the units "in front" of a unit:
You'd basically first choose all the units in some range R, and then you can narrow it down to who is in that "sector" of the circle.

Lastly, when the unit gets "stuck", they'll end up being issued a stop order. So you may need to re-issue the order so the unit continues to make progress.

This will help with any intentional unit obstructions that happen--but won't account for cases where the unit gets stuck for other reasons (e.g. if there is no path that leads to the target point).

Here is a sample map that has a high-elf running to a circle of power. That "move" order gets issued and tracked in the system in "IssueMoveOrder". You can press ESC to attempt to surround the unit. If enough time passes, one unit in front of it will be killed, allowing the high-elf to continue. Feel free to tweak it or copy the triggers over into your map if needed! (there is one JASS function, IsUnitInSector, in the map header that you'll also need to copy)
 

Attachments

  • SurroundSample.w3m
    61.2 KB · Views: 3
Top