Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

need a script to make npc activate trigger when player is insight

Share questions, scripts and tutorials related to the ScriptAPI in SFD.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
The_JOKER
Fighter
Fighter
Posts: 38
Joined: Mon Jul 18, 2016 2:35 am
Title: I'm Korean JOKER :)
SFD Account: JOKER_Korea
SFD Alias: JOKER
Started SFD: April 2016
Location: South Korea
Gender:
Age: 17
Contact:

need a script to make npc activate trigger when player is insight

Post by The_JOKER » Mon Jul 02, 2018 1:37 am

I'm making a payday map and I need a script to make npc activate certain trigger when player is insight

-it shouldn't work when player is BEHIND the npc
-it shouldn't work when player insight is npc
-it shouldn't applied to all npcs but only certain npcs
-there must be a custom range that npc can spot player
-I need both on enter method and on leave method
(on enter and on leave will activate different trigger)
-npc can't spot players below or above the npc

please tell me if any of these are not possible.
0 x

ClockworkDice
Fighter
Fighter
Posts: 27
Joined: Wed Nov 02, 2016 12:59 am
Started SFD: Sometime in Pre-Alpha
Gender:

Post by ClockworkDice » Wed Jul 04, 2018 6:57 pm

What I would do is test whether or not the player is within a rectangle in front of the npc. You can use IPlayer.FacingDirection to determine which way they are facing. The problem with that suggestion is that they would be able to see players through walls if the rectangle extended far enough. You could have a sort of "raycasting" system where you shoot 0 damage bullets out of the npc towards the player and see if they hit, but I'm not sure if that is possible. Maybe there's a way to use the laser sight for raycasting
0 x

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 375
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 20

Post by JakSparro98 » Wed Jul 04, 2018 9:38 pm

The_JOKER wrote:
Mon Jul 02, 2018 1:37 am
I'm making a payday map and I need a script to make npc activate certain trigger when player is insight

-it shouldn't work when player is BEHIND the npc
-it shouldn't work when player insight is npc
-it shouldn't applied to all npcs but only certain npcs
-there must be a custom range that npc can spot player
-I need both on enter method and on leave method
(on enter and on leave will activate different trigger)
-npc can't spot players below or above the npc

please tell me if any of these are not possible.
As @ClockworkDice already said, what you're trying to achieve is called "raycast" and the only way to obtain a solid result is a bit too heavy to be used with lots of NPCs in final maps outside prototypes (like my AI script).
Image
If you are asking, that's not impossible as you can see in this gif, I used that for a robust way to make my AI to shoot when the target is on sight, but there's a lot of overhead in the raycast calculation process, resulting in a huge lag.

You need to specify in what kind of situation (environment scheme) you will need these sort of "sentry" NPCs so we can chose to opt (or not) for using a raycast solution or a lighter workaround.
0 x

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1245
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 28

Post by Gurt » Wed Jul 04, 2018 9:52 pm

I would love to support better native RayCast support in the ScriptAPI but it's nothing we prioritize right now.
3 x
Gurt

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest