| 01-08-2009, 11:35 PM | #1 |
im trying to figure out the best way to get a unit to follow another unit without 'Amov'. First way I tried was SetUnitFacing(follower, Angle Between Follower & Folowee) & PolarProjection(GetUnitFacing()...), but it's too easy to get stuck on trees and whatnot. Next was making an invisible unit that is ordered to move to the folowee, then having the follower unit PolarProject to the angle between itself and the "pather" unit. This method proved to have really unpredictable pathing (thanks blizzard) and sometimes it would take downright retarded routes anyone have any ideas? |
| 01-09-2009, 12:23 AM | #2 |
I would suggest moving the follower yourself, using coordinates and angles as well as setting facing. You'd set the animation of the unit to walk via SetUnitAnimationByIndex, which is heavily dependent on the unit's model and it's walk animation index. |
| 01-09-2009, 12:52 AM | #3 |
Why not use your second approach, but instead do: JASS:call SetUnitX(yourNoAmovUnit, GetUnitX(yourDummyPatherUnit)) call SetUnitY(yourNoAmovUnit, GetUnitY(yourDummyPatherUnit)) |
| 01-09-2009, 03:36 AM | #4 | |
Quote:
It's a good idea, but there's a few problems: 1. I can't get the pather unit to spawn EXACTLY where the follower is standing. I've messed with the collision, offset the X/Y by 1, and I still cant get it to spawn ontop of it 100% of the time. 2. Because the movement is all triggered, the "run speed" of the nonAmov unit is just the distance it gets polarprojected. So if I just set the X/Y to the postion of the pather, the run speed would be all fucked up |
| 01-09-2009, 04:15 AM | #5 |
Then use a breadcrumb technique. pseudocode:
breadcrumb linkedlist crumbs // use a linked list here
function periodic
local breadcrumb
if ParentIsMoving then
crumbs.addLast(newParentCrumb()) // basically storing the unit's position here
call moveChildTo(crums.first)
call crums.first.destroy()
endif
endfunctionso if the parent moves, it lays crumbs and the child will only go to the next crumb when the parent lays a new crumb. The number of crumbs would allow you to provide a general follow distance (or delay in this case). If you want to improve performance, you can skip multiple crumbs and interpolate between 2 crumbs. edit: think of this as a final fantasy follow routine (when the rest of your party follows behind the leader). |
| 01-09-2009, 04:52 AM | #6 | |
Quote:
I'm not sure how to use linked lists But I'd personally just make a struct, have a timer calling a method that lays a crumb (stores the X/Y in 2 real arrays?) IF the pather is @ least someDistance (the runspeed amount) from the last crumb is there anyway around using sqroute for the bolded part? |
| 01-09-2009, 05:56 AM | #7 |
JASS:globals constant real YourDistance = 500.*500. endglobals //... // in function set tempDist = (dx*dx)+(dy*dy) // dx/dy are the change in x/y (x2 - x1). if tempDist > YourDistance then // whatever you want |
| 01-09-2009, 10:07 AM | #8 | |
Quote:
you kind of lost me there. could you explain it differently please? |
| 01-09-2009, 10:39 AM | #9 | |
Quote:
Ammorth's function executes if the square of both distances is greater than the square of the max distance. In other words, it's a spinoff of the pythagorean theorum. Building off ammorth here: JASS:globals timer t unit gpather unit gleader constant integer maxdist = 128*128 endglobals function PatherHandler takes nothing returns nothing local real dx = GetUnitX(gpather) - GetUnitX(gleader) local real dy = GetUnitY(gpather) - GetUnitY(gleader) if(dx*dx + dy*dy > maxdist)then call SetUnitX(gpather, GetUnitX(gleader), GetUnitY(gleader) endif endfunction function EstablishPather takes unit pather, unit leader returns nothing set gpather = pather set gleader = leader call TimerStart(t, .05, true, function PatherHandler) endfunction What that would do is make it so every time pather gets 1 terrain square away it teleports it to the leaders position |
| 01-09-2009, 07:49 PM | #10 |
I would use IsUnitInRangeXY or IsUnitInRange to prevent collision dist problems. |
