- Home /
transform.TransformDirection setting a size?
I am shooting raycasts and was wondering if there is a way to set a size for the raycast? Right now its shooting forever until it hits something. Im trying to set a specific length or size to the raycast.
RaycastHit hitInfo;
Vector3[] direction = new Vector3[5];//Array of Raycasts
void Raycasting(){
this.direction[0] = transform.TransformDirection (new Vector3(-1f,0f,3))*3;
this.direction[1] = transform.TransformDirection (new Vector3(-.5f,0f,3))*3;
this.direction[2] = transform.TransformDirection (new Vector3(0f,0f,3))*3;
this.direction[3] = transform.TransformDirection (new Vector3(.5f,0f,3))*3;
this.direction[4] = transform.TransformDirection (new Vector3(1f,0f,3))*3;
}
If you look at the documentation for the Physics.Raycast there is an argument for theRaycast called 'distance' which is what you need.
Answer by PokeJoe · Feb 25, 2015 at 09:50 AM
http://docs.unity3d.com/ScriptReference/Physics.Raycast.html
The third parameter of the Physics.Raycast() function is the distance, which should be given as a float. By the way, what you have is not an array of Raycasts, but an array of Vector3s, which are only one component necessary to do a Raycast (which is a function, something you do, not an object, something you have).
So when you call the function later on, make sure you specify the distance.
Thanks a bunch that helped me clear things up. Works great now. Here's my code that I did to fix it. Hopefully it will help someone. It's in a for loop.
Physics.Raycast(transform.position, this.direction[i],out hitInfo, 10.0f)