Pressing "Space" while near NPC to start a conversation
Posted: Thu Jan 18, 2024 5:46 am
Hello, I just bought this amazing product. I am really enjoying all that it has to offer.
Is it possible for the Player, while being in the NPC's collider area, to press "space" for the conversation to trigger instead of it appearing automatically?
I am struggling to find a way to do this. Any help is much appreciated. Thank you Pixel Crushers!
---------------------------
I found the answer!
Re: 2D conversation trigger
Post by Tony Li ยป Thu Aug 05, 2021 5:53 pm
Hi,
First make sure you've ticked the Dialogue System Welcome Window's USE_PHYSICS2D checkbox.
Add a trigger collider and rigidbody2d to the NPC. Tick the collider's Is Trigger checkbox. Since you want conversations to work within a certain radius, use a Circle Collider 2D and set the radius. You can set the rigidbody2d to Kinematic so it affected by physics forces such as gravity.
Then add a collider and rigidbody2d to the player. You can set the rigidbody2d to Kinematic.
Make sure the player and NPC are on layers that will register physics collisions. (Check the matrix in Edit > Project Settings > Physics 2D.)
Once you've done the basic Unity physics setup above, you can set up the Dialogue System part:
On the NPC, add a Usable component and Dialogue System Trigger. On the Dialogue System Trigger, select Add Action > Start Conversation. Select the conversation you way to play.
On the player, add a Proximity Selector component and Selector Use Standard UI Elements component.
Then test it out. When the player enters the NPC's trigger collider radius, you should see a yellow selector message such as: "NPC / (spacebar to interact)". Press the space bar. It should start the conversation. You can also click the right mouse button since it's mapped to the input named "Fire2".
If you want to start conversations with left mouse click, change the Use Key to "mouse 0" or change the Use Button to "Fire1".
Top
Is it possible for the Player, while being in the NPC's collider area, to press "space" for the conversation to trigger instead of it appearing automatically?
I am struggling to find a way to do this. Any help is much appreciated. Thank you Pixel Crushers!
---------------------------
I found the answer!
Re: 2D conversation trigger
Post by Tony Li ยป Thu Aug 05, 2021 5:53 pm
Hi,
First make sure you've ticked the Dialogue System Welcome Window's USE_PHYSICS2D checkbox.
Add a trigger collider and rigidbody2d to the NPC. Tick the collider's Is Trigger checkbox. Since you want conversations to work within a certain radius, use a Circle Collider 2D and set the radius. You can set the rigidbody2d to Kinematic so it affected by physics forces such as gravity.
Then add a collider and rigidbody2d to the player. You can set the rigidbody2d to Kinematic.
Make sure the player and NPC are on layers that will register physics collisions. (Check the matrix in Edit > Project Settings > Physics 2D.)
Once you've done the basic Unity physics setup above, you can set up the Dialogue System part:
On the NPC, add a Usable component and Dialogue System Trigger. On the Dialogue System Trigger, select Add Action > Start Conversation. Select the conversation you way to play.
On the player, add a Proximity Selector component and Selector Use Standard UI Elements component.
Then test it out. When the player enters the NPC's trigger collider radius, you should see a yellow selector message such as: "NPC / (spacebar to interact)". Press the space bar. It should start the conversation. You can also click the right mouse button since it's mapped to the input named "Fire2".
If you want to start conversations with left mouse click, change the Use Key to "mouse 0" or change the Use Button to "Fire1".
Top