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.
Proximity Selector unreliable
Re: Proximity Selector unreliable
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.
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.
-
- Posts: 81
- Joined: Wed Jun 24, 2020 5:06 pm
Re: Proximity Selector unreliable
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.
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);
}
}
}
Re: Proximity Selector unreliable
Hi,
Unity calls OnControllerColliderHit() whenever you try to move a character controller.
Perhaps you want to use OnCollisionEnter() instead.
Unity calls OnControllerColliderHit() whenever you try to move a character controller.
Perhaps you want to use OnCollisionEnter() instead.
-
- Posts: 81
- Joined: Wed Jun 24, 2020 5:06 pm
Re: Proximity Selector unreliable
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)
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)
Re: Proximity Selector unreliable
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.
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.
-
- Posts: 81
- Joined: Wed Jun 24, 2020 5:06 pm
Re: Proximity Selector unreliable
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. Don't know why it was only triggered when hitting the wall but it doesn't matter, it's fixed now.
Re: Proximity Selector unreliable
No worries; I'm glad it's working now!