- Home /
Raycast length must be equal to the target distance
supose that an enemy raycast hit a crate, i want the raycast length to be the same as the (enemy , crate) distance...and when the raycast doesn't hit something i want it to be equal let say float 10; i tried but it doesnt work HELP ME PLEASE... this is what i made
var RayHitDist:float=10;
var RayTarget:Transform;
function Update(){
var RTdistance=Vector3.Distance(RayTarget.position,Owner.position);
var RayLong=transform.TransformDirection(Vector3.forward);
var Rayhit: RaycastHit;
Debug.DrawRay(RayPos.position,RayLong*10,Color.green);
if(Physics.Raycast(RayPos.position,RayLong,Rayhit,RayHitDist)) { RayTarget=Rayhit.transform; RayHitDist=RTdistance;
if(Rayhit.collider.gameObject.tag=="Ennemy"){AimTarget=false;}
if(Rayhit.collider.gameObject.tag=="Player"){AimTarget=true;}
}
if ( RayTarget==null ) { RayHitDist=10; }
}
Answer by Jep · Oct 18, 2012 at 05:29 AM
Try putting RTdistance inside the if like:
if(Physics.Raycast(RayPos.position,RayLong,Rayhit,RayHitDist)){
RTdistance = Vector3.Distance(RayPos.position, Rayhit.collider.gameObject.transform.position);
RayHitDist=RTdistance;
}
thx you...and i tried for the null assignment...but i cant
when the ray cast doent collide i want it to be equal to 10
Answer by hotozi · Oct 19, 2012 at 07:21 AM
thx you...and i tried for the null assignment...but i cant
when the ray cast doent collide i want it to be equal to 10
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
RAYCAST KNOWLEDGE HELP!!! 1 Answer
Physics.Raycast not checking layermask properly? 1 Answer
changing guiTexture color with raycast 1 Answer
Make Raycast that ignores certain tags? 0 Answers