How to check if npc is in range of player's interaction range
How to check if npc is in range of player's interaction range
I want to somehow check if npc is in player's range, what important my player can be in different scene than the npc. If npc is in players range then some button show above the npc which can start dialogue. I don't see any events that might help me with that. Is there a possibility to do that simple enough. I don't want to check conditions every update iteration etc.
Re: How to check if npc is in range of player's interaction range
I don't really know how to do it. My case is a little bit different from proximity approach. As I said I want to setactive of the UI gameobject with image and button on it when player is in npc's range, but I don't see any range in proximity selector, since it works with triggers, I guess I should add collider for npc and player, but I am not sure. Can you explain me more
Re: How to check if npc is in range of player's interaction range
Hi,
Looking at the example image in the Proximity Selector manual page:
you can see that the NPC has a sphere trigger collider that defines its interaction range. It also has a Usable component to tell the Dialogue System that it's detectable by Proximity Selector. When the player is inside the trigger collider, the Proximity Selector will detect the NPC. Please see the Interaction Tutorial video for more details about how to set it up.
Looking at the example image in the Proximity Selector manual page:
you can see that the NPC has a sphere trigger collider that defines its interaction range. It also has a Usable component to tell the Dialogue System that it's detectable by Proximity Selector. When the player is inside the trigger collider, the Proximity Selector will detect the NPC. Please see the Interaction Tutorial video for more details about how to set it up.
Re: How to check if npc is in range of player's interaction range
I changed selector on proximity, but that approach doesnt work for some reason :/ I'll include player and npc objects with their components. I guess it should work, and my dialogue icon should be visible when player npc is in player's trigger range, and should be invisible when player is out of it. But nothing happends. What important I don't know if that might be the problem, but I use 3 dialogue triggers attached to same gameobjct. Two of them are enabling, disabling icon, and third one is for on use which starts conversation, this method is invoking when player clicks on the icon.
- Attachments
-
- Dialogue icon
- Zrzut ekranu_20230105_162404.png (127.48 KiB) Viewed 509 times
-
- Dialogue trigger attached to parent which is npc #3
- Zrzut ekranu_20230105_161943.png (95.53 KiB) Viewed 509 times
-
- Dialogue trigger attached to parent which is npc #2
- Zrzut ekranu_20230105_161935.png (199.67 KiB) Viewed 509 times
-
- Dialogue trigger attached to parent which is npc #1
- Zrzut ekranu_20230105_161916.png (129.47 KiB) Viewed 509 times
-
- Dialogue selector attached to parent which is player
- Zrzut ekranu_20230105_161842.png (136.69 KiB) Viewed 509 times
Re: How to check if npc is in range of player's interaction range
If you want to use the Dialogue System's selector/usable system, it's much simpler than that. Where do you want the icon to appear? At a consistent screen position? (For example, in DemoScene1 the selector UI appears at the top of the screen.) Or above the NPC's head?
You don't have to use the Dialogue System's selector/usable system. You can use your own system instead. In that case, just configure your own system to call the Dialogue System Trigger's OnUse() method.
You don't have to use the Dialogue System's selector/usable system. You can use your own system instead. In that case, just configure your own system to call the Dialogue System Trigger's OnUse() method.
Re: How to check if npc is in range of player's interaction range
The icon should appear above the npc's head in world space. I don't really know what is wrong with that, I would like to use dialogue system for that if possible.
Re: How to check if npc is in range of player's interaction range
I am struggling with it, trying many different things and it still doesn't work So as I said my dialogues icons which on click should start each dialogue should appear above each npc when player is in his range, if player isn't then they should disappear or be hidden. That's the functionality I want to get. I hope you can help me!!
Re: How to check if npc is in range of player's interaction range
Also I guess standard ui selector elements is just one object, so when I have many npc's on my scene that probably won't help me. Also what's even more important, my npc's can be on different scenes while player is on different, I see that there is a warning that standard ui elements don't found on the scene.
Re: How to check if npc is in range of player's interaction range
As described in the Interaction Tutorial video, you can add a (world space) StandardUsableUI prefab to the NPC. When the ProximitySelector detects the NPC, it will show this UI instead of the standard screen space one. Here's an example scene (based on DemoScene1) that adds the Basic Standard Usable UI prefab to Private Hart. It also replaces the player's Selector with a ProximitySelector.
DS_TestProximitySelectorUsableUI_2023-01-09.unitypackage
Note: If you don't want to work with Proximity Selectors and Usable UIs, you can always use your own interaction system and configure it to call the NPC's DialogueSystemTrigger.OnUse(). The whole Selector/Proximity Selector thing is entirely optional.
DS_TestProximitySelectorUsableUI_2023-01-09.unitypackage
Note: If you don't want to work with Proximity Selectors and Usable UIs, you can always use your own interaction system and configure it to call the NPC's DialogueSystemTrigger.OnUse(). The whole Selector/Proximity Selector thing is entirely optional.