Hi everyone. I have it mostly done, except for this one bug.
I have a boolean called, isInteracting which starts obviously as false.
If I’m inside a certain range from the target object, I begin shooting rays to colliders looking for that object’s tag, if I look at it, isInteracting equals true.
The issue I have is that if I keep looking at it and leave the range, the isInteracting does not come back to false.
By now, I know it’s because the player is always in contact other collider (the ground) and because of that, I cannot set isInteracting to false when the player is not in the range of the target collider, because its always happening!
Any help is really appreciated
Player interact class code:
public bool isInteracting;
// Update is called once per frame
void FixedUpdate()
{
// Check for nearby colliders looking for the parchment.
Collider[] colliderArray = Physics.OverlapSphere(transform.position, interactRange);
foreach (Collider collider in colliderArray)
{
Debug.Log(collider.tag);
if (collider.tag == "parchment")
{
// Shoot a ray when in range to make sure the player is looking at it.
Debug.Log("1");
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit))
{
if (hit.collider.tag == "parchment")
{
Debug.Log("2");
isInteracting = true;
Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow, 1.0f);
}
else
{
Debug.Log("3n");
isInteracting = false;
}
}
}
}
}