How to make two rays with different offset follow objects rotation?

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 :slight_smile:

If you want to make a direction be relative to a given transform, use

actualDir = transfom.TransformDirection(localDir);

This will give you the correct direction at any given time. If you also need the Offset to be relative to the transform, use

actualOffset = transform.TransformPoint(localOffset);

Both of these return Vector3 which can be used in raycasting as you need.