Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: stylez75 on Fri 05/11/2021 20:15:00

Title: Have NPC turn in the direction of Player and detect seeing them
Post by: stylez75 on Fri 05/11/2021 20:15:00
Can anyone point me in the right direction for scripting this?

I have the NPC randomly walking left or right in the room. If the NPC turns either to their right or left and the player is their then display something like you are dead.

I tried using something like
Code (age) Select

if (cJIm.x<=cEgo.x)
{
  Display("You are dead");
}

but doesn't seem to do the trick with detecting if the NPC is facing the player.

thanks for any help.
Title: Re: Have NPC turn in the direction of Player and detect seeing them
Post by: Cassiebsg on Fri 05/11/2021 21:24:55
check for player.Loop as well.  :)
Title: Re: Have NPC turn in the direction of Player and detect seeing them
Post by: stylez75 on Sat 06/11/2021 15:21:27
Thanks the loop worked
Code (ags) Select

    if ((cJIm.Loop==1) && (cEgo.x<=cJIm.x))
        {
          cJIm.Say("I see you player on LEFT. You are no dead");
        }
       
        if ((cJIm.Loop==2) && (cEgo.x>=cJIm.x))
        {
          cJIm.Say("I see you player on RIGHT. You are no dead");
        } 
Title: Re: Have NPC turn in the direction of Player and detect seeing them
Post by: Crimson Wizard on Sat 06/11/2021 15:31:22
Note that you may use existing constants instead of bare numbers, they correspond to the walking loop values:
Code (ags) Select

enum CharacterDirection {
  eDirectionDown,
  eDirectionLeft,
  eDirectionRight,
  eDirectionUp,
  eDirectionDownRight,
  eDirectionUpRight,
  eDirectionDownLeft,
  eDirectionUpLeft,
  eDirectionNone
};


So, like
Code (ags) Select

if ((cJIm.Loop==eDirectionLeft) && (cEgo.x<=cJIm.x))

and so on.
It's more text, but may be easier to understand what it means.