Results 1 to 7 of 7

Thread: Regarding GetFacing function

  1. #1
    Basic Member
    Join Date
    Feb 2015
    Posts
    15

    Regarding GetFacing function

    Hello guys,

    Does anyone know what the value returned by this function means ? (ie: which number means I'm facing North, West, ... ?)
    On Moddota, it wrote that this function returns value from 0 to 255 but when I debugged I think that value range isn't correct (-100 to 450 from what I saw, maybe wrong though)
    And also if we have an unit and a location, is there any code to know if that unit is facing directly to the location ?

    Thanks in advance.

    Note: Sorry for bad English, I'm not a native speaker.

  2. #2
    Basic Member
    Join Date
    Jun 2013
    Posts
    275
    It goes by 360 degrees. 0-359. So Moddota's values are incorrect.
    Facing East is 0, North is 90, West is 180, South is 270.

    I haven't done any experimenting with facing directly at a location, but you can use GetBot():GetFacing() to return the bots facing degree. You might be able to work something out with that.

  3. #3
    Basic Member
    Join Date
    Dec 2016
    Posts
    32
    when i was figuring out what the function returns i got that confusing -100 to 450 result, but when i assumed that its the facing angle in degree:
    Code:
            local SELF_ANGLE=math.rad(npcBot:GetFacing());
            local SELF_VEC=Vector( math.cos(SELF_ANGLE),math.sin(SELF_ANGLE),0);
            DebugDrawLine(npcBot:GetLocation(),npcBot:GetLocation()+SELF_VEC*1000,255,0,0);
    the debug line is pointing the facing direction of the unit (with poor precision).
    Quote Originally Posted by antigame View Post
    is there any code to know if that unit is facing directly to the location ?
    calculate the dot product of the facing vector and the vector from the unit to the target location, if the result is around -1 then the unit is facing the target.(idk if there is a built in library for vectors, i calculated it manually).
    i wrote a code to let slark pounce correctly to a target:
    Code:
    		   if(npcBot:GetActiveMode() == BOT_MODE_ATTACK)
    		   then
                       local TARGET=npcBot:GetTarget();
                       local DIS=GetUnitToUnitDistance(npcBot,TARGET);
                            if(DIS<=POUNCE_RADIUS)then
                            ----------------------------------------------------
                                    local TARGET_LOCATION=TARGET:GetLocation();
                                    local SELF_LOCATION=npcBot:GetLocation();
                                    local ENEMY_VEC_NO_NORM=SELF_LOCATION-TARGET_LOCATION;
                                    local ENEMY_VEC=Vector(ENEMY_VEC_NO_NORM.x/DIS,ENEMY_VEC_NO_NORM.y/DIS,0);
                                    local DOT=(ENEMY_VEC.x*SELF_VEC.x)+(ENEMY_VEC.y*SELF_VEC.y);
                            ----------------------------------------------------
                                    if(DOT>=-1 and DOT<=-0.96)then
                                            CAST_ABILITY(npcBot,"slark_pounce",false);
                                            CAST_ABILITY(npcBot,"slark_dark_pact",false);
                                    end
                            end
    		   end
    hope this help (feel free to correct me if im wrong).
    Last edited by DzeeRay; 01-03-2017 at 07:29 AM.

  4. #4
    Basic Member
    Join Date
    Feb 2015
    Posts
    15
    Thanks alot guys, really appreciate it.
    A little off topic: How to find out the coordinate of any location on the map ? (like fountain, jungle, random location, ...). I want to do it myself instead of google it but don't know how.
    Last edited by antigame; 01-03-2017 at 09:12 AM.

  5. #5
    Basic Member
    Join Date
    Jun 2013
    Posts
    275
    Quote Originally Posted by antigame View Post
    Thanks alot guys, really appreciate it.
    A little off topic: How to find out the coordinate of any location on the map ? (like fountain, jungle, ...). I want to do it myself instead of google it but don't know how.
    The simple way is to enter a custom game without filling empty slots with bots and using the console command cl_showpos 1. It'll give the x, y and z coordinates that the bottom-middle of the camera is over. So you just hover over the position you want the coordinates to and it'll give you accurate enough x and y values. z is less helpful since the camera is hovering above the map.
    You can use hud_toggle_visibility in the console as well to remove the UI so you can more clearly see where the bottom of the screen is hovering over.

    If you want precision, you can open the map in the Hammer map editor as part of the Dota 2- Tools and use the 2D wire cameras to get exact coordinates.

    I use the map editor if I'm trying to get threading-the-needle ward locations. Other than that I use the in-game camera method since it's a lot faster if I'm trying to gather a number of coordinates at once. Because I don't really need exact numbers if I just want the Bot to move within range of a shop or fountain. XD
    Last edited by Cornbane; 01-03-2017 at 09:41 AM.

  6. #6
    You can use the IsFacingLocation function in my Utility.lua file (you can find the file here).

  7. #7
    Basic Member
    Join Date
    Feb 2015
    Posts
    15
    Quote Originally Posted by Cornbane View Post
    The simple way is to enter a custom game without filling empty slots with bots and using the console command cl_showpos 1. It'll give the x, y and z coordinates that the bottom-middle of the camera is over. So you just hover over the position you want the coordinates to and it'll give you accurate enough x and y values. z is less helpful since the camera is hovering above the map.
    You can use hud_toggle_visibility in the console as well to remove the UI so you can more clearly see where the bottom of the screen is hovering over.

    If you want precision, you can open the map in the Hammer map editor as part of the Dota 2- Tools and use the 2D wire cameras to get exact coordinates.

    I use the map editor if I'm trying to get threading-the-needle ward locations. Other than that I use the in-game camera method since it's a lot faster if I'm trying to gather a number of coordinates at once. Because I don't really need exact numbers if I just want the Bot to move within range of a shop or fountain. XD
    Thanks, guess I will use the camera method then

    Quote Originally Posted by Platinum_dota2 View Post
    You can use the IsFacingLocation function in my Utility.lua file (you can find the file here).
    Thank dude, I saw your thread and it's amazing, will definitely check it for any useful function for my bots

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •