draw line starting position

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lowpolygon

I have been following this tutorial on ray casting

It is a very well written tutorial and I can understand it quite nicely up to this line

draw_line(Vector2(), (hit_pos - position).rotated(-rotation), laser_color)

I looked up help document , the first parameter is where the line starts to draw, in this case it is a location of a turret. Which I would assume the line should be something like

 draw_line(position, (hit_pos - position).rotated(-rotation), laser_color)

script is attached to turret hence the position.
But when I tested , the line is drawn from top of the screen to the target. And if I changed back to vector2() then, it the line would be drawn correctly from turret to target

I am a bit confused on why it is. Am I missing something here ?

:bust_in_silhouette: Reply From: Dlean Jeans

When you draw_line the positions you pass is relative to the node you draw on not absolute. So Vector2() passed in becomes position and passing position as the first arguments means the line will start at position + position.

Because of this, if the turret could move, you will likely see the start point of the line moving around.

Thank you. It actually make a lot of sense, I just wish the help doc in Godot could be more clear about this

lowpolygon | 2019-06-11 01:19