I don't know what I'm doing wrong, so hopefully someone will want to give some quick advice.
The player object is controlled by the keyboard (WASD, Enter/Return), and it activates objects around him when the player presses Enter. I don't want the object to activate unless the player is facing the object, so I tried to use Raycasting from the player to the collider object (now simply a cube) that surrounds the object:
The above method returns true if the ray coming from the player hits something, false if it doesn't.
Now for the Box collider:
canTalk is a boolean that returns true if the player's collider hits the trigger that surrounds the cube. player.GetComponent().IsFacingObject() is the method I showed you above, returning true or false.
However, player.GetComponent().IsFacingObject() doesn't return true, even though the player is facing the cube and is even touching the cube. Why isn't the raycast seeing the cube?
asked Jun 11 '10 at 01:44 AM
Start by using Debug.DrawRay on IsFacingObject to ensure that the raycast would actually be hitting something. Without seeing the scene, it's possible that your object's pivot (transform.position) is higher than the top of the cube, and that your ray is overshooting it.
answered Jun 11 '10 at 07:06 AM