Warcraft III resources & community, 2003–2006 · archived

Line of Sight Checker(Bullet Immitator)

not rated
Submitted by ZerglebPhysics0 downloads
This checks to see if a line between 2(3-Dimensional) points would ever intersect into the terrain of a map(Not the dodadds, just the ground including platform heights), if the line would intersect into the terrain, if you choose to save, it will save the FIRST point of intersection, and then the 2 functions GetSavedImpactHeight and GetSavedImpactLocation will give you these values(GetSavedImpactLocation will create a new location object, and yes I know GetSavedImpactHeight is pointless)

Hopefully I didn't mess anything up when I changed a few lines that were different because of my specific game(They were there in bad programming habit anyways).

This will not find if a dodadd or other obstacles are intersecting the line, but I do have a method of achieving this but it is a bit messy and its as efficient as it could be or cleanly versatile yet(Versatile meaning working outside of just my one game), after I clean that code up a bit I might post.

Bullet Immitator-
Since I call it a bullet immitator I might as well explain myself, The basic idea is you have the position of the attacking unit as the FromLoc and the position of the attacked object as the ToLoc. And for the heights you kind of just guesstimate.... I know its crude but it's the best I can come up with at the moment. I suggest just alot of testing to see if the guesses are accurate enough.

I also create an effect at udg_bj_LastKeptLoc and damage the unit if the function returns true. I've been experimenting with creating a flying unit as the effect and setting the fly height to udg_bj_LastKeptHeight The only real problem is when the terrain height is a negative number. and then the unit flys at 0 instead of whatever negative number.


Global Variables needed:
udg_bj_LastKeptLoc
udg_bj_LastKeptHeight

Source

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////Line of Sight Functions///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function GetSavedImpactHeight takes nothing returns real
    return udg_bj_LastKeptHeight
endfunction

function GetImpactLocation takes nothing returns location
    return Location(GetLocationX(udg_bj_LastKeptLoc), GetLocationY(udg_bj_LastKeptLoc))
endfunction

function KeepImpactLocation takes location KeepLoc, real KeepHeight returns nothing
    call RemoveLocation(udg_bj_LastKeptLoc)
    set udg_bj_LastKeptLoc = KeepLoc
    set udg_bj_LastKeptHeight = KeepHeight
endfunction

//FromHeight and ToHeight are to be the height off the ground, as opposed to giving the height of the ground plus the height off the ground, the function
adds the height of the ground in itself.
    
function CheckLineOfSight takes location FromLoc, real FromHeight, location ToLoc, real ToHeight, boolean Save returns boolean
    local location KeeperLoc = Location(GetLocationX(FromLoc), GetLocationY(FromLoc))
    local real KeeperStopDistance = DistanceBetweenPoints(FromLoc, ToLoc)
    local real KeeperTravelDistance = 0
    local real TravelAngle = AngleBetweenPoints(FromLoc, ToLoc)
    local real KeeperHeight = GetLocationZ(FromLoc) + FromHeight
    local real TravelSlope = ((GetLocationZ(ToLoc) + ToHeight ) - (GetLocationZ(FromLoc) + FromHeight)) / (DistanceBetweenPoints(FromLoc, ToLoc))
    local boolean LocFound = false
    local boolean Result = false
    loop
       exitwhen LocFound
        //if the ground is higher than the bullet, then stop the bullet//  
        if ( KeeperTravelDistance >= KeeperStopDistance ) then
            set LocFound = true
            set Result = true
        elseif (GetLocationZ(KeeperLoc) >= KeeperHeight) then
          set LocFound = true
        endif
             if LocFound then
                 if Save then
                     if Result then
                         call KeepImpactLocation(Location(GetLocationX(ToLoc), GetLocationY(ToLoc)), (GetLocationZ(ToLoc) + ToHeight))
                     else
                         call KeepImpactLocation(Location(GetLocationX(KeeperLoc), GetLocationY(KeeperLoc)), KeeperHeight)
                     endif
                 endif
                 call RemoveLocation( KeeperLoc )
                 set KeeperLoc = null
             else
                 call MoveLocation(KeeperLoc, GetLocationX(KeeperLoc) + 10 * Cos(TravelAngle * bj_DEGTORAD), GetLocationY(KeeperLoc) + 10 * Sin(TravelAngle * bj_DEGTORAD))
                 set KeeperHeight = KeeperHeight + (TravelSlope * 10)
                 set KeeperTravelDistance = KeeperTravelDistance + 10 
             endif
    endloop
    return Result
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Comments

0

No comments.