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.
Line of Vision
Started by
SpacemanDan
, Aug 28 2011 04:18 PM
2 replies to this topic
#1
Posted 28 August 2011 - 04:18 PM
#2
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.
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);
}
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
Posted 30 August 2011 - 09:35 AM
Works beautifully. Thank you for that!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users