0 votes

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 ?

asked Jun 10, 2019 in Engine by lowpolygon (164 points)
edited Jun 10, 2019 by lowpolygon

1 Answer

0 votes
Best answer

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.

answered Jun 10, 2019 by Dlean Jeans (3,917 points)
selected Jun 11, 2019 by lowpolygon

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.