|
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?
(comments are locked)
|
|
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. That was basically it. The ray was undershooting the cube and missing the mark. It is fixed now. Thanks!
Jun 12 '10 at 05:03 AM
cyangamer
(comments are locked)
|
