Project Sylvanas docs axiombot.net Discord

Follow your target

Follows the current target, a player or a mob, and stops 4 yd short. A re-aimed move_to never stops the walk: the character walks on, and the new route takes over when it arrives.

local EVERY_MS = 500     -- once a second or every half second is plenty
local KEEP_YD = 4
local last = 0

core.register_on_update_callback(function()
    local client = _G.AXIOM_NAV and _G.AXIOM_NAV.client
    if not client then return end

    local now = core.time()
    if now - last < EVERY_MS then return end
    last = now

    local me = core.object_manager.get_local_player()
    if not me or not me:is_valid() then return end
    local target = me:get_target()
    if not target or not target:is_valid() or target:is_dead() then
        if client:is_moving() then client:stop() end
        return
    end

    local pos = target:get_position()
    if me:get_position():dist_to(pos) <= KEEP_YD then
        if client:is_moving() then client:stop() end
        return
    end

    client:move_to(pos)    -- the same spot (under 1.5 yd off) is ignored, so a still target costs nothing
end)

Notes

  • Do not call it every frame for a moving unit. Every 0.5 to 1 s is enough, and only one route is asked at a time.
  • To keep away from other mobs while following, add { avoid_mobs = true }. A walk that ends inside a mob's ring (the one you follow) is never bent away from it.