Hi guys I have problem with draw raycast. I want to draw raycast from one gameobject to other one I use it in update :
But ray draw in other point. Yes from start positon but end position is not in second gameobject position. Why ?
I need it to check a 3 radomlny direction.x to make waypoints. Meybe you know other good way to make waypoints ? Meybe you can tell me how can I use a empty gameobject to make waypoint list ?
DrawRay and Raycast don’t work the same. They are really close, which causes the confusion. Plus, rayCasts are tricky to begin with.
RayCast takes a direction and an optional distance. So D=(100,0,50) or D=(10,0,5) or D=(2,0,1) all tell raycast to shoot forwards and a little left. No matter which one you use, something like,
RayCast(start, D, 50) will shoot 50 units forward and right. The technical term is that raycast treats D as a direction.
DrawRay does care about how big D is. In technical terms, it treats D as a vector. It draws the ray exactly that many units forward and right. There’s no straight-forward way to tell DrawRay to just go until it hits something. But…
If your direction is length 1, you can DrawRay where the rayCast went by saving the distance to the hit and “puffing out” the DrawRay direction by that much. It requires a RaycastHit, let’s say named
rayHit. Use that in: