I’m trying to learn about Raycasting and am trying to use it to open a treasure chest. Basically, the chest will cast a ray that goes out a certain distance and if it collides with a gameobject tagged player, it should play an animation to open the treasure chest. For some reason, it is not recognizing the collision. Any Ideas?
public Animation chestOpen;
public RaycastHit hit;
void openTreaure()
{
if(Physics.Raycast(transform.position, Vector3.forward, out hit, 200.0F))
{
if(hit.collider.gameObject.tag == "Player" )
{
print("In Range");
animation.Play("box_open");
}
}
}