Proximity Selector unreliable

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
gblekkenhorst
Posts: 83
Joined: Wed Jun 24, 2020 5:06 pm

Proximity Selector unreliable

Post by gblekkenhorst »

I've been trying to figure this out for a few days and I've hit a wall. The proximity selector to trigger NPC dialogue only sometimes works. It seems slightly more likely to trigger if I hit the input key twice.

I have this in the Update loop of the ProximitySelector script:

if (Input.GetKeyDown(KeyCode.E))
{
Debug.Log("Is key down " + IsUseButtonDown());
}

And it seems to randomly come back true or false. Is there anything in your experience that could be causing this? Nothing else in the scene is changing, the player is just standing there.
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: Proximity Selector unreliable

Post by Tony Li »

Hi,

Is your code at the beginning of the Update() method? If it's later in the method, is it possible that something earlier in the method is exiting the method early?

If not, is something temporarily disabling the Proximity Selector component? Disabled components don't run Update.
gblekkenhorst
Posts: 83
Joined: Wed Jun 24, 2020 5:06 pm

Re: Proximity Selector unreliable

Post by gblekkenhorst »

If I disable the proximity selector, I can't interact with the NPCs at all.


The problem seems to have fixed itself when I removed the trigger from the player. I'm usuaing a character controller to control the player, and it seems like having a trigger collider on the player, even if it was small, was interfering with the dialogue system somehow?

But have another situation where I am trying to set off an alert on collision, and now I'm using OnControllerColliderHit instead of Trigger. For some reason, the alarm is going off, but then it never goes away, no matter what the length is set to and how far away from the object that triggered it is.

Code: Select all

    private void OnControllerColliderHit(ControllerColliderHit hit)
    {
        
       
        if (hit.gameObject.tag == "Block")

            Debug.Log("TriggerAlert");
            DialogueManager.ShowAlert(alertMessage + " Block " + hit.gameObject.name, length);

            if (_input.move.x == 0 && _input.look.x ==0)
            { _animator.Play("Idle");
                GetComponent<CharacterController>().velocity.Set(0, 0, 0);

            }

        } 

       

    }
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: Proximity Selector unreliable

Post by Tony Li »

Hi,

Unity calls OnControllerColliderHit() whenever you try to move a character controller.

Perhaps you want to use OnCollisionEnter() instead.
gblekkenhorst
Posts: 83
Joined: Wed Jun 24, 2020 5:06 pm

Re: Proximity Selector unreliable

Post by gblekkenhorst »

It's fine if it only happens when they move, as the play runs into it. The issue is the alert doesn't disappear when the player stops moving, or once the player moves away from the wall. The debug log stops, but the alert doesn't dissappear.

I tried oncollisionenter earlier, it's not working because a rigidbody on either the player or the wall would need to be kinematic, so they don't register each other. (I tried changing the project settings to Enable all contact pairs and it didn't change anything, but that has nothing to do with dialogue system)
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: Proximity Selector unreliable

Post by Tony Li »

I think one of two things could be happening:

1. The alert panel is not being deactivated. Maybe the 'length' value that you're passing is too long.

2. Or it's constantly calling DialogueManager.ShowAlert() and showing the alert every frame because OnControllerColliderHit() may be called every frame if the player is moving into the collider.
gblekkenhorst
Posts: 83
Joined: Wed Jun 24, 2020 5:06 pm

Re: Proximity Selector unreliable

Post by gblekkenhorst »

On my goodness, I'm so embarrassed. I was missing a bracket after the conditional checking the tag, so it was triggering the Debug.Log properly, but the alert was being triggered by everything, including the road the player was standing on. :oops: Don't know why it was only triggered when hitting the wall but it doesn't matter, it's fixed now.
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: Proximity Selector unreliable

Post by Tony Li »

No worries; I'm glad it's working now! :-)
Post Reply