• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] How to walk through trees only?

Level 4
Joined
Feb 1, 2024
Messages
36
Title says itself. I'd like to give a ground unit ability to walk through trees only, so they are still blocked by terrains.

I don't think turn collision within certain range of tree would work since if the unit fire another trigger that turns collision on, they will be instantly blocked among trees again.
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
The "unit firing another trigger that turns collision on" would be a fairly easy thing to fix, you just use a counter system for modifying collision:
  • Example
    • Events
      • Something happens
    • Conditions
    • Actions
      • Set Variable Collision_Unit = (Some unit)
      • Trigger - Run Disable Collision (ignoring conditions)
  • Disable Collision
    • Events
    • Conditions
    • Actions
      • Set Variable Collision_CV = (Custom value of Collision_Unit)
      • Set Variable Collision_Counter[Collision_CV] = (Collision_Counter[Collision_CV] + 1)
      • If all conditions are true then do Actions
        • If - Conditions
          • Collision_Counter[Collision_CV] Equal to 1
        • Then - Actions
          • Unit - Turn collision for Collision_Unit off
        • Else - Actions
  • Enable Collision
    • Events
    • Conditions
    • Actions
      • Set Variable Collision_CV = (Custom value of Collision_Unit)
      • Set Variable Collision_Counter[Collision_CV] = (Collision_Counter[Collision_CV] - 1)
      • If all conditions are true then do Actions
        • If - Conditions
          • Collision_Counter[Collision_CV] Equal to 0
        • Then - Actions
          • Unit - Turn collision for Collision_Unit on
        • Else - Actions
This uses the Unit Indexing method that relies on custom value. A very useful system to have in your map for tracking data. The last thing to do would be to reset a unit's Collision_Counter back to 0 when it gets "recycled" by the Unit Indexer. The system provides an Event and variable for this:
  • Reset Collision Counters
    • Events
      • Game - UnitIndexEvent becomes Equal to 2.00
    • Conditions
    • Actions
      • -------- Basically when a unit dies the system "recycles" it's custom value. This means that a new unit can be given this custom value. --------
      • -------- Let's reset any old data that was attached to this custom value (UDex) so the new unit doesn't inherit any previous changes. --------
      • Set Variable Collision_Counter[UDex] = 0

Otherwise, maybe rely on the SetUnitX/Y functions to ignore collision.
 
Last edited:
Level 11
Joined
May 29, 2008
Messages
132
I've actually spent quite a while thinking about this and there's just no good way to do it in WC3. Treant Protector never had this ability in DotA 1 AFAIK. Instead he had invisibility near trees which is much easier.

You could try to do some continuous checking to see if the unit is near a tree but not on a cliff and toggle their pathing as appropriate, but I don't think it will feel very smooth and the pathing engine might still try to walk around the trees. And it will also be okay walking over some cliffs, which it shouldn't do. I decided that the player experience was too annoying for it to be worth adding to the hero I was designing.
 
Level 19
Joined
Feb 27, 2019
Messages
590
I had an idea and it seems to work.

1. Remove the pathing from the destructible.
2. Trigger it so that the terrain containing the destructible is not pathable by walkability or any other pathability a destructible would hinder.
3. Add the amphibious pathablility to the terrain.
4. Add the amphibious movement type to the unit.

A problem with this is that units with the amphibious movement type can walk in deep water. (Lets say no units should walk in deep water, easy, just remove that terrain pathability from deep water.

At least one could mess around with this and it would require a change of terrain pathability if the destructible dies etc.
 
Top