I have a simple code which is supposed to keep my “ship” hovering over ground on small distance using raycast. It works nice, but i don’t know if i could make it work better if i would be able to see this raycast, which i can’t see normally as it’s really long and strangely pointed. I just want to know what’s wrong with those raycasts lines.
Here’s my code i’m using to keep my ship alligned parallel (x-axis) to track as an example for drawing those lines:
var offset1 = new Vector3(0,0,3);
var offset2 = new Vector3(0,0,-3);
var dir1 = new Vector3(0,-2,3).normalized;
var dir2 = new Vector3(0,-2,-3).normalized;
function FixedUpdate(){
if (Physics.Raycast (transform.position + offset1, dir1, 0.4)){
transform.Rotate (Vector3 (1,0,0));
}
if (Physics.Raycast (transform.position + offset2, dir2, 0.4)){
transform.Rotate (Vector3 (-1,0,0));
}
Debug.DrawLine(transform.position + offset1, dir1 * 1, Color.green);
Debug.DrawLine(transform.position + offset2, dir2 * 1, Color.green);
}
btw. I’m using simple cube as ship as i thought that my model is bad…