Unit circles idly after SetUnitMoveGoal completes

Unit circles idly after SetUnitMoveGoal completes

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
tzaeru
Posts: 283
Joined: 28 Oct 2007, 02:23

Unit circles idly after SetUnitMoveGoal completes

Post by tzaeru »

Heya, I've a simple custom command set up that issues raw move orders, mostly copied from ZK's https://github.com/ZeroK-RTS/Zero-K/blo ... w_move.lua

The issuing looks like so:

Code: Select all

Spring.SetUnitMoveGoal(unitID, cmdParams[1],cmdParams[2],cmdParams[3],64,nil,true)
And it works. But once the order finishes, the unit starts circling, instead of coming to a full stop.

This is the original ZK code + my modification for the command callins:

Code: Select all

function gadget:UnitCmdDone(unitID, unitDefID, unitTeam, cmdID, cmdTag)
if (cmdID == CMD_RAW_MOVE) then
Spring.Echo("Unit cmd done")
Spring.ClearUnitGoal(unitID)
spGiveOrderToUnit(unitID, CMD.STOP, {}, {})
else
return false
end
end

function gadget:CommandFallback(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOptions) -- Only calls for custom commands
if (cmdID ~= CMD_RAW_MOVE) then
return false
end

local x, y, z = spGetUnitPosition(unitID)
local distSqr = GetDistSqr({x, y, z}, cmdParams)
if (distSqr > (64)) then
return true, false -- command was used but don't remove it(unit have not reach destination yet)
else
--spGiveOrderToUnit(unitID, CMD.STOP, {}, {})
Spring.Echo("Removing cmd..")
return true, true -- command was used, remove it (unit reached destination)
end
end
UnitCmdDone gets called as appropriate, but the orders issued within it seem to not do much anything.

Ideas for how to stop the unit after SetUnitMoveGoal finishes?
User avatar
PepeAmpere
Posts: 591
Joined: 03 Jun 2010, 01:28

Re: Unit circles idly after SetUnitMoveGoal completes

Post by PepeAmpere »

I would append that this is not trivial problem if we consider fact, that engine is not 100 % reliable in reporting commands finished. The failure rate based on our experiments is that at least 1 command in 10000 is not reported properly as finished.

If you consider Spring engine as a black box you cannot trust :) there are some ways you can still do as a user of this black box. Here are 7 steps we used for estimating that robots group move was finished. It was used during the NOE AI framework development around 2012 and we returned to this problem few months ago as part of the BETS project:

Next is the evolution of the function of the "group move in formation completed" event on lua scripters side.
  • 1. add tolerance for all members from target positions
    2. not all members need to be in position, just pointman
    3. not all members need to be in position, just some percent
    4. avg distance of all members is smaller than...
    5. avg distance smaller than + distance of the most distant member smaller than...
    6. logic of iteration 5 + timeout
    7. logic of iteration 5 + specific handling of hilly areas and unreachable points
As I stated somewhere, evaluation function around 4-5th level starts to be robust enough for the most of the usecases.

If your problem is really just stopping the unit, do not use SetUnitMoveGoal and use normal CMD.MOVE.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Unit circles idly after SetUnitMoveGoal completes

Post by Kloot »

For internal reasons, only a new regular move command can stop a unit after using raw movement.
tzaeru
Posts: 283
Joined: 28 Oct 2007, 02:23

Re: Unit circles idly after SetUnitMoveGoal completes

Post by tzaeru »

PepeAmpere wrote:If your problem is really just stopping the unit, do not use SetUnitMoveGoal and use normal CMD.MOVE.
The thing is that I want to invoke StartMovingRaw, which is called by SetUnitMoveGoal if the last parameter is 'true'. The idea is to skip the whole pathfinder.

And it otherwise works, just that I can't figure out how to bring the unit to a halt once it reaches its goal and the command is removed. :)
Kloot wrote:For internal reasons, only a new regular posting.php?mode=quote&f=23&p=581203move command can stop a unit after using raw movement.
Ah, hm. I'll try what happens if I just tell it to go to its current location..
tzaeru
Posts: 283
Joined: 28 Oct 2007, 02:23

Re: Unit circles idly after SetUnitMoveGoal completes

Post by tzaeru »

tzaeru wrote:
Kloot wrote:For internal reasons, only a new regular posting.php?mode=quote&f=23&p=581203move command can stop a unit after using raw movement.
Ah, hm. I'll try what happens if I just tell it to go to its current location..
Woo, it works exactly as intented. Thanks, Kloot!

Still a few problems in queuing multiple such commands (it seems to always go for the last goal, but CommandFallback gets 1st goals parameters) but I think those are purely related to how BA itself handles order queues and the like.
Post Reply

Return to “Lua Scripts”