• 🏆 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!

Creep curving, and how to fix it.

Level 2
Joined
Jul 21, 2012
Messages
5

How to: Fix Warcraft 3 creep pathfinding.

What is the problem, man?

A few months ago, when I decided to create my own Tower Defense, I had a lot of trouble with creeps: they just didn't want to walk in a straight line. You see, when you pick a unit and order him to move somewhere far away, he "curves", and goes a little bit to the side of his target, and then, when he's almost there - he changes directions and comes to the right place.
This can be extremely annoying in some cases.
Let me show you an illustration.
attachment.php

Here is a map called "Path test" which is pretty self-explanatory. It has a trigger:
  • Events
  • Player - Player 1(red) types a chat message containing next as Exact match
  • Actions
  • Unit - Create 1 Dryad for Player 1(red) at (Center of Location 000 <gen) facing 270.00 degrees.
  • Unit - Order(last created unit) to Move (Center of Location 001 <gen)
And when you type "next" to run the trigger, your dryad runs down and a bit to the right, almost running off the brick road.
Like that:
Top point:
attachment.php

Middle point:
attachment.php

Bottom point:
attachment.php

Her trajectory is like that:
attachment.php

And she runs on a purple line instead of a red one.
Now, most people recommend using path blockers, increasing the number of locations, but these ways are not always applicable, and creep movement still remains weird. And I know that is not really important ^^ but is visually implausible and can turn your Maze-like TD with a lot of narrow paths into a mess.

So, what should we do?

Simply change your unit's property "Movement - Type" to "Hover", and "Pathing - Collision Size" to 1.
And her trajectory now is correct:
attachment.php

Yes, it is simple as that =)

Thank you!

And by the way, you can check out a map in the attachment to see it for yourself.
 

Attachments

  • MoveDryadTest.w3m
    12.1 KB · Views: 235
  • 2.jpg
    2.jpg
    43.9 KB · Views: 2,597
  • 1.jpg
    1.jpg
    44.1 KB · Views: 2,574
  • 3.jpg
    3.jpg
    34 KB · Views: 2,579
  • 4.jpg
    4.jpg
    116.8 KB · Views: 2,626
  • 5.jpg
    5.jpg
    118.8 KB · Views: 2,613
  • 6.jpg
    6.jpg
    39.5 KB · Views: 2,624
Last edited by a moderator:
Level 6
Joined
May 4, 2012
Messages
187
So simple, maybe? I recommend you to add another picture/screenshot featuring that the dryad walked real straight in the line, in that way, even if without testing it would be much more believable. Also I THINK this is somewhat short, mind in adding additional informations or other things? :D
 
Level 2
Joined
Jul 21, 2012
Messages
5
Whoa, that was quick! Thank you for your feedback, everyone.
Silly me, I forgot to attach a test map. =)
And you'll need to change the creep's size as well to make it work.(that's what happens when you spend half of your day in the WE ^^")
iChaos
I've added a bit more info and screenshots - hope that helps.
Radamantus
Yes, I know that regions are not very efficient and there are better ways - but I chose them to exclude possible creep collision problems.
 
Hmm yeah it doesn't seem to work. Actually, the fields that he refers to "Path-Size" doesn't seem to exist (in the object editor, anyway). Maybe he is using a different language for his editor. If anyone knows which fields he is referring to, PM me. Otherwise, I'll send this to the graveyard for now since it doesn't seem to work.

Sorry about the confusion.
 
Level 23
Joined
Jan 1, 2009
Messages
1,608
No, I still don't get why this is approved.
Even in the test map, when I set the dryad to hover and collision 1, it still curves - just in a slightly different pattern.
ft41OQ.jpg

In this pic the Tank has Hover and collision 1, while the wandigo has Foot and collision 0. I cannot see much if any different in their curving behavior.
Horizontal works better than vertical for both, but in any direction both start to curve on longer distances (as illustrated by trackmarks/footsteps)

Please provide a testmap with 2 units, one curving and one definitely not curving, because as it stands this is still useless.
 
Level 13
Joined
Nov 7, 2014
Messages
571
It seems that adding a small term (-1.0, -0.01, etc) to the x component of the destination location fixes this?

JASS:
struct Loc
    real x
    real y

    static method from takes unit u returns thistype
        local thistype this = thistype.allocate()
        set this.x = GetUnitX(u)
        set this.y = GetUnitY(u)
        return this
    endmethod

    method angle_to takes Loc other returns real
        return Atan2(other.y - this.y, other.x - this.x) * bj_RADTODEG
    endmethod
endstruct

struct Path
    Loc start
    Loc end
    real direction // degrees

    static method new takes Loc start, Loc end returns thistype
        local thistype this = thistype.allocate()
        set this.start = start
        set this.end = end
        set this.direction = start.angle_to(end)
        return this
    endmethod

    method spawn takes integer uid returns boolean
        local unit u = CreateUnit(Player(0), uid, this.start.x, this.start.y, this.direction)
        if u == null then
            return false
        endif

        // call IssuePointOrder(u, "move", this.end.x, this.end.y)

        // =) ???
        // call IssuePointOrder(u, "smart", this.end.x - 1.0, this.end.y)
        call IssuePointOrder(u, "move", this.end.x - 0.01, this.end.y)

        set u = null
        return true
    endmethod
endstruct
 

Attachments

  • unit-pathfinding-curving.w3x
    28.5 KB · Views: 76
Level 23
Joined
Jan 1, 2009
Messages
1,608
It seems that adding a small term (-1.0, -0.01, etc) to the x component of the destination location fixes this?
Are you a little stupid or a lottle?
I don't think there is any reliable way to fix this, since this is directly part of how the pathfinding AI works.

The only real "fix" would be coding your own pathing algorithm and moving all units via SetUnitX/Y periodically.
Well I can think of others, e.g. splitting up the path into segments that dont curve and then order the creep along via timer.

But if it were a simple ObjectData fix, that would be way more convenient.
 
Level 23
Joined
Jan 1, 2009
Messages
1,608
It seems to work for the example in the unit-pathfinding-curving.w3x map that's attached to the post.

No, and if you would have tested the map properly you would know that.
It works on small distances and with his specific setup, but you can produce curving by simply moving the blue circles into the corners,
or making the map bigger and moving them outwards.

Hence the question - because it should be obvious that units and orders might have arbitrary values in normal gameplay anyway. Why would adding some value change this.

proof3.gif

as muzzel said there is no reliable way.
 
Level 13
Joined
Nov 7, 2014
Messages
571
but you can produce curving by simply moving the blue circles into the corners,
or making the map bigger and moving them outwards.
Ah, yeah I see... this is rather funny =). I tried it in melee gameplay and it does happen although I can't say I have ever noticed it before because one usually moves their units at small distances (1 screen or less) or larger distances but the map usually has obstacles that units naturally go around so its hard to notice.

I guess a workaround would be to add more points to the path that are between the start and end points of each segment because this curving seems to occur/is noticeable when the path segment is "longish".
 
Top