- Home /
Raycast lines debug problem
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...
This code doesn't look like it'll be smoothly rotating you anywhere. There's nothing in there to check how close you are to the middle, so it'll end up oscillating wildly around the correct value, never actually stabilising. What are offset1, offset2, dir1 and dir2? Are they lines pointing down from each 'wing' of your object? What is the desired behaviour here? Do you want the thing to align itself to the terrain?
In this question i wanted to know why my raycast lines are so long, becouse if i can't see my raycasts then i can't allign them as i want them to using "offset1, offset2, dir1, dir2". Those lines are (one on the back of ship and one on the front) supposed to keep it alligned to my track.
Oh! Well, if you just want to know why your lines are drawing so funny, that's easy.
Answer by syclamoth · Nov 13, 2011 at 08:28 AM
You're using Debug.DrawLine instead of Debug.DrawRay. That's why your lines are looking funny!
Your answer
![](https://koobas.hobune.stream/wayback/20220613041841im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
script is not working Using raycast show PopUp on click 0 Answers
GUI label on raycast? 0 Answers
problem with touch android 0 Answers
problem with raycasting and functions 1 Answer
Problem with raycast 0 Answers