Map limits for a unit in movement

Zeth

Member
Reaction score
3
Hello.

I have a spell that moves an unit periodically to forward (with SetUnitPosition function).

But when the unit reaches the limits of the map (where is the "black area"), it continues moving.

How do i stop the unit when it reaches the "black area"?

Something like this:

JASS:
if GetUnitX(a)==MapLimitX or GetUnitY(a)==MapLimitY then
call KillUnit()
endif


??

Thanks, and "sorry for my bad english". :D
 

Laiev

Hey Listen!!
Reaction score
188
[lJASS]GetWorldBounds()[/lJASS] returns a rect, you should use [lJASS]GetRectMaxX(GetWorldBounds())[/lJASS], [lJASS]GetRectMaxY(GetWorldBounds())[/lJASS], [lJASS]GetRectMinX(GetWorldBounds())[/lJASS] and [lJASS]GetRectMinY(GetWorldBounds())[/lJASS]
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Just implement this into your map.
JASS:
library BoundSentinel initializer init
//*************************************************
//* BoundSentinel
//* -------------
//*  Don't leave your units unsupervised, naughty
//* them may try to get out of the map bounds and
//* crash your game.
//*
//*  To implement, just get a vJass compiler and
//* copy this library/trigger to your map.
//*
//*************************************************

//==================================================
   globals
       // High enough so the unit is no longer visible, low enough so the
       // game doesn't crash...
       //
       // I think you need 0.0 or soemthing negative prior to patch 1.22
       //
       private constant real EXTRA = 500.0
   endglobals

   //=========================================================================================
   globals
       private real maxx
       private real maxy
       private real minx
       private real miny
   endglobals

   //=======================================================================
   private function dis takes nothing returns nothing
    local unit u=GetTriggerUnit()
    local real x=GetUnitX(u)
    local real y=GetUnitY(u)

       if(x>maxx) then
           set x=maxx
       elseif(x<minx) then
           set x=minx
       endif
       if(y>maxy) then
           set y=maxy
       elseif(y<miny) then
           set y=miny
       endif
       call SetUnitX(u,x)
       call SetUnitY(u,y)
    set u=null
   endfunction

   private function init takes nothing returns nothing
    local trigger t=CreateTrigger()
    local region  r=CreateRegion()
    local rect    rc

       set minx=GetCameraBoundMinX() - EXTRA
       set miny=GetCameraBoundMinY() - EXTRA
       set maxx=GetCameraBoundMaxX() + EXTRA
       set maxy=GetCameraBoundMaxY() + EXTRA
       set rc=Rect(minx,miny,maxx,maxy)
       call RegionAddRect(r, rc)
       call RemoveRect(rc)

       call TriggerRegisterLeaveRegion(t,r, null)
       call TriggerAddAction(t, function dis)

    //this is not necessary but I'll do it anyway:
    set t=null
    set r=null
    set rc=null
   endfunction
endlibrary

It will stop any unit from sliding out the map.
Don't have to put a check in your code.
 

Laiev

Hey Listen!!
Reaction score
188
this library prevent any unit move outside the map.. if some missile are moving forward the playable area map, this system just set the position of the unit to limit of map
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top