Have NPC turn in the direction of Player and detect seeing them

Started by stylez75, Fri 05/11/2021 20:15:00

Previous topic - Next topic

stylez75

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

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.

Cassiebsg

There are those who believe that life here began out there...

stylez75

Thanks the loop worked
Code: ags

    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");
        }  

Crimson Wizard

Note that you may use existing constants instead of bare numbers, they correspond to the walking loop values:
Code: ags

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


So, like
Code: ags

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

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

SMF spam blocked by CleanTalk