Page 1 of 1

Selector - proximity to game objects rather than mouse

Posted: Sat Aug 14, 2021 5:46 am
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!

Re: Selector - proximity to game objects rather than mouse

Posted: Sat Aug 14, 2021 9:05 am
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)

Re: Selector - proximity to game objects rather than mouse

Posted: Sat Aug 14, 2021 10:59 am
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.

Re: Selector - proximity to game objects rather than mouse

Posted: Sat Aug 14, 2021 11:31 am
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.

Re: Selector - proximity to game objects rather than mouse

Posted: Sat Aug 14, 2021 12:01 pm
by lostmushroom
I still can't get it working. Would you mind if I send you a repro project?

Re: Selector - proximity to game objects rather than mouse

Posted: Sat Aug 14, 2021 12:38 pm
by Tony Li
Sure, that's fine. Please include the steps I should follow to reproduce the issue.

Re: Selector - proximity to game objects rather than mouse

Posted: Sat Aug 14, 2021 2:24 pm
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.