Author Topic: Check if NPC is facing PC  (Read 314 times)

Legacy_Sturmdolch

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Check if NPC is facing PC
« on: February 07, 2011, 10:15:06 pm »


               Hello,

I am working on a line-of-sight stealth based singleplayer module. A big goal here is getting guards to patrol, and when they see the PC, they teleport the PC back to start.

Here's what I have so far:




void main()

{

  int nEvent = GetUserDefinedEventNumber();

  if (nEvent == 1002) // OnPerceive event

  {

    object oPC = GetLastPerceived();
    float fCheck = GetDistanceToObject(oPC);

         if(GetIsPC(oPC) && GetLastPerceptionSeen()&& (fCheck <= 8.0f)  )
        {

          ClearAllActions();

          ActionJumpToObject(oPC);

          ActionStartConversation(oPC);

  }
  }
}

But, the orientation of the NPC does not seem to matter. Even if I run past behind them, I'll get sent to the start.

Is it somehow possible to get the NPC to only perceive the PC if they are also facing their general direction?

Thanks!
               
               

               


                     Modifié par Sturmdolch, 07 février 2011 - 11:27 .
                     
                  


            

Legacy_Xovian

  • Full Member
  • ***
  • Posts: 158
  • Karma: +0/-0
Check if NPC is facing PC
« Reply #1 on: February 08, 2011, 12:52:55 am »


               As far as I recall, visual spotting is based entirely on the Spot Skill which does use a facing check, though I'm not sure how big of a cone it uses. Don't quote me on that, as it's been a few years, I'd have to go back through using the Biosearcher to check it which i cant while at work.

Another factor that often gets over looked for such things is the Listen skill (and a few feats in the toolset) and those ignore direction and are based on a radius to detect (the feat version is a flat 60 radius).

So if you havne't checked that, it is probably the bigger "cause" of your problem, and is at least worth looking into. I have no idea if there is a work around for how the spot skill is being used as to my knowledge it's one of the hard coded constants. Perhaps someone else might be willing to chime in with a bit more detail.
               
               

               


                     Modifié par Xovian, 08 février 2011 - 01:07 .
                     
                  


            

Legacy_Sturmdolch

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Check if NPC is facing PC
« Reply #2 on: February 08, 2011, 10:13:17 pm »


               Thanks for the reply. I was trying to bypass the "listen" with GetLastPerceptionSeen(), but that didn't change anything.



I might just have to go with NPCs that have a 360 degree detect radius around them.