I have a pad I interact with in my game. How do I make a visual indicator like the one shown in the attached GIF? You see that there is a circle that appears on the tablet showing where the user is about to click.
I have a collider around the tab and on the index finger.
I have tried two methods that did not work for me. One of them is instantiating the game object I intend using as the indicator when the index finger's collider enters the collider around the tablet and then updating its local position to be that of the index finger and some offset. I then destroy it OnTriggerExit.
The indicator kind of move with the index finger but I could not get the exact behaviour I want. I'm also trying my best possible to avoid using Update()
Here is the method I tried that is closer to what I want:
public GameObject visualIndicator;
private float _moveSpeed = 15f;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("indexFinger"))
{
reticle.SetActive(true);
}
}
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("indexFinger"))
{
Vector3 targetPosition = other.ClosestPoint(transform.position);
visualIndicator.transform.position = Vector3.Lerp(visualIndicator.transform.position, targetPosition, Time.deltaTime * _moveSpeed);
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("indexFinger"))
{
reticle.SetActive(false);
}
}
For this, I initially have the visual indicator set inactive on the pad. I also have a collider on the pad that protrudes out a bit such that once the finger collider collides with it, the visual indicator is set active and its position is updated to be the position of the point of collision in OnTriggerStay.
This looks very close to what I want but the visual indicator moves a bit up from the pad when looked from the side because its position is updated to be the point of collision of the pad's collider and the finger's. I want the visual indicator to only stay on the pad and follow the finger as shown in the following GIF:
