- Home /
Infinite ray length
Hello. Im trying to make an infinite ray lengh but I have no idea how to do it. I know how to make a limited length ray and I do it like this
var rayLength : float = 100;
var hit : RaycastHit;
var forward = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position,
forward, hit, rayLengh))
{
code();
}
How do I make it infinite ? Thank you. I hope I was clear enough.
The code im using :
function Shoot()
{
var hit : RaycastHit;
var forward = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, forward, hit, Mathf.Infinity))
{
var Gun : Transform;
Gun = Instantiate(bullet, barrelEnd.position, transform.rotation);
Gun.LookAt(hit.point);
w();
wep.animation.Play("Shoot");
audio.PlayOneShot(shootSoundEffect);
}
}
TransformDirection Transforms direction from local space to world space.
Vector3.forward is already in world space. Its the z axis, I believe.
Answer by stevethorne · Aug 06, 2014 at 04:44 PM
If you don't pass in a distance, it will automatically be infinite. Alternatively, you can pass in Mathf.Infinity
It won't actualy work. Dunno why. I updated my question with my main code. Thank you for your time tho!
Yeah ,sorry. BTW that's just an example of the script. Im using the second one.
Your answer
Follow this Question
Related Questions
Raycasting issue for maximised screen 2 Answers
how detect "OnRaycastOut" 1 Answer
Raycast Not Drawing In Target Direction? 0 Answers
Raycast hitdetection not working correctly 2 Answers
Raycast not visible 1 Answer