Selector - proximity to game objects rather than mouse

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
lostmushroom
Posts: 195
Joined: Mon Jul 01, 2019 1:21 pm

Selector - proximity to game objects rather than mouse

Post by lostmushroom »

Hey Tony, I'm doing a game jam and just realised I don't know how to do a really simple thing. I made a basic character controller (a cube moving up and down) and have a few interactable NPCs around the scene. I'd like for the selector to pick up when the cube is in proximity to the NPCs rather than using mouse position, but I'm not sure how to do it.

I don't think Centre Screen will be right because there's no moving camera in this game, it's just a static screen. And I'm guessing I'd use Distance From: Game Object rather than Camera? Anyway I've messed around with it for a while and can't get it working so I thought I'd ask :)

Thanks!
User avatar
Tony Li
Posts: 22159
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selector - proximity to game objects rather than mouse

Post by Tony Li »

Hi,

On the player, remove the Selector component. Add Rigidbody (or Rigidbody2D in 2D), collider, Proximity Selector and Selector Use Standard UI Elements.

On the cube(s), add a Rigidbody (tick Is Kinematic), Usable, and Dialogue System Trigger. On the Dialogue System Trigger, select Add Actions > Start Conversation, and select your conversation.

Make sure the player's layer and the cube's layer are configured to register collisions. (Edit > Project Settings > Physics)
lostmushroom
Posts: 195
Joined: Mon Jul 01, 2019 1:21 pm

Re: Selector - proximity to game objects rather than mouse

Post by lostmushroom »

Thanks Tony - I just tried that out but can't seem to get it working. Just a couple of questions to check I did it right:

- The "player cube" also needs a Rigidbody, Usable and Dialogue System Trigger, or just the NPC cubes? The cube is currently a child of the player game object, in case that makes a difference.

- All cubes are on the default layer and in my physics settings, default collisions are enabled, so that should be ok? Or is there something else I need to check.
User avatar
Tony Li
Posts: 22159
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selector - proximity to game objects rather than mouse

Post by Tony Li »

Hi,

The player cube only needs a Rigidbody, [Box]Collider, and Proximity Selector. Put the Proximity Selector on the cube -- the same GameObject that has the Rigidbody and collider. It's okay if this is a child of the main player GameObject.

The NPC cube only needs a Rigidbody, collider, Usable, and Dialogue System Trigger. The Usable and Dialogue System Trigger should be on the same GameObject that has the Rigidbody and collider.
lostmushroom
Posts: 195
Joined: Mon Jul 01, 2019 1:21 pm

Re: Selector - proximity to game objects rather than mouse

Post by lostmushroom »

I still can't get it working. Would you mind if I send you a repro project?
User avatar
Tony Li
Posts: 22159
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selector - proximity to game objects rather than mouse

Post by Tony Li »

Sure, that's fine. Please include the steps I should follow to reproduce the issue.
User avatar
Tony Li
Posts: 22159
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selector - proximity to game objects rather than mouse

Post by Tony Li »

Hi,

Thanks for sending the repro project.

One of the colliders -- either the player's Cube or the Egg -- must be a trigger collider. Tick the 'Is Trigger' checkbox on one.
Post Reply