- Home /
Raycasting Help
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");
}
}
}
It is in the update method directly below. All of this is attached to the treasure chest object in my scene, and the player object does have the player tag.
Answer by Depento · Nov 07, 2014 at 09:06 PM
I figured it out.... As it turns out, the Treasure chest was on a slightly lower plane than the player. It was a dumb mistake on my part....
Your answer
Follow this Question
Related Questions
Problem with raycasting, checking for ground doesn't work 3 Answers
[C#] UNET Client raycast not the same as Server raycast 2 Answers
Raycast causes all enemies to attack 1 Answer
How to check if an empty GameObject is inside an object? 2 Answers
Instantiate an object at hit position without it intersecting anything 1 Answer