Jump to content

Photo

Line of Vision


  • Please log in to reply
2 replies to this topic

#1 SpacemanDan

SpacemanDan

  • Members
  • Location:Ontario, Canada

Posted 28 August 2011 - 04:18 PM

I thought this would be easy to make, but I just can't seem to get it to work. DX

Basically, I'd be looking for a function/method that checks if Link is within the line of vision of a specified coordinate. (Obviously, there'd have to be a check for what direction this thing is looking in.)

I mostly need it for an enemy that only shoots when Link is in its line of sight yet I can not get it to work quite right. DX

Any help would be greatly appreciated.

#2 Isdrakthül

Isdrakthül

    Apprentice

  • Members

Posted 28 August 2011 - 06:15 PM

I wrote a function similar to that for an L-targeting script a while ago. It is from Link's perspective instead of the enemy's, but I think it could be modified to be the other way around. int width is the width of the area in which Link can be seen. Bear in mind that it makes no provision for hiding behind objects.

CODE

int width = 80;
bool isTarget(npc me)
{
    if(Link->Dir == DIR_UP){
        if((me->X+me->HitXOffset) <= (Link->X+((width-16)/2)+15) && (me->X+me->HitWidth+me->HitXOffset-1) >= (Link->X-((width-16)/2))){
            if((me->Y+me->HitYOffset) <= (Link->Y+15)) return(true);
        }
    }
    else if(Link->Dir == DIR_DOWN){
        if((me->X+me->HitXOffset) <= (Link->X+((width-16)/2)+15) && (me->X+me->HitWidth+me->HitXOffset-1) >= (Link->X-((width-16)/2))){
            if((me->Y+me->HitYOffset+me->HitHeight-1) >= Link->Y) return(true);
        }
    }
    else if(Link->Dir == DIR_LEFT){
        if((me->Y+me->HitYOffset) <= (Link->Y+((width-16)/2)+15) && (me->Y+me->HitHeight+me->HitYOffset-1) >= (Link->Y-((width-16)/2))){
            if((me->X+me->HitXOffset) <= (Link->X+15)) return(true);
        }
    }
    else{
        if((me->Y+me->HitYOffset) <= (Link->Y+((width-16)/2)+15) && (me->Y+me->HitHeight+me->HitYOffset-1) >= (Link->Y-((width-16)/2))){
            if((me->X+me->HitXOffset+me->HitWidth-1) >= Link->X) return(true);
        }
    }
    return(false);
}


#3 SpacemanDan

SpacemanDan

  • Members
  • Location:Ontario, Canada

Posted 30 August 2011 - 09:35 AM

Works beautifully. Thank you for that! icon_biggrin.gif


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users