I have an object with 2 rays with an different offset: one ahead and one on the back of this object. This object rotates on Y-axis and it needs those 2 rays follow his rotation (that is, one on back must be always be on its back and the one ahead… always ahead). How do i do that?
My code:
var offset1 = Vector3(0,0,0.5);
var offset2 = Vector3(0,0,-0.5);
var dir1 = Vector3(0,-1,0.5).normalized;
var dir2 = Vector3(0,-1,-0.5).normalized;
var RayLenght : float = 0.2;
function FixedUpdate(){
if (Physics.Raycast (transform.position + offset1, transform.forward + dir1, RayLenght)){
transform.Rotate (Vector3 (-0.1,0,0));
}
if (Physics.Raycast (transform.position + offset2, transform.forward + dir2, RayLenght)){
transform.Rotate (Vector3 (0.1,0,0));
}
}
Or if someone have better idea of keeping an object parallel to track whole time i would be grateful