Howdy, I want to be able to use Ray Casting in an FPS so that when my FPC walks near to an object on the floor an animation plays. My problem is that with my current code the ray casting only connects with objects directly in-front of the player. Can anybody tell me how to change the position/angle of my ray casting so that it will be colliding with the floor a certain distance in front of my player.
Here is the code I'm currently working with.
function Update()
{
var hit : RaycastHit;
//check if we're colliding
if(Physics.Raycast(transform.position, transform.forward, hit, 5))
{
//...with a plane
if(hit.collider.gameObject.tag == "orangeplane")
{
//change colour!
hit.collider.gameObject.animation.Play("orange");
}
}
}
Any suggestions on how to do this would be greatly appreciated, Will.