How to draw a dotted line demonstrating the raycast path

Thanks @ross.grams

I am really unaware of this.

Now If I want to create method to draw lines what I have to do any suggestions.
I want to create method somthing like draw_line(start_point, end_point, dist_between_dots) to draw lines so I can easily create multiple lines and update the lines so I can draw raycast rays replacing those debug draw_line.

2 Likes

You should probably read the script properties manual then: Script component properties


Hmm, well it’s probably not going to work exactly the same way as the debug “draw_line”. The script you have now only handles one straight line per script, so you would need a separate script instance for each line segment, which is not convenient at all. Hmm…

I would probably use a lua module. Put the draw_dotted_line function in the module and change it so instead of using ‘self’, all the things it needs are passed in as arguments. Pass in the ‘self.dot_ids’ list, and an optional ‘start index’ so you can use the same list of IDs for multiple line segments.

-- Something like this...
drawLine(start_pt, end_pt, dist_between_dots, factory_url, dot_ids, [first_dot_id_index])

It’ll need to return the last dot index that it used so you know which index to start with for the next line segment.

Separate the dot destroying/hiding part into a separate function in the module, which you’ll use after drawing all of your lines.

Once you have those things working you could add another function to the module to draw a full polyline from a list of points (it’ll just call the other module functions for you, taking care of the boilerplate stuff).


On another note, it would be slightly better if you only update the line when you need to—probably on mouse move instead of update.

2 Likes

I found that DrawPixels is good enough to do such a job.

function on_input(self, action_id, action)
  drawpixels.fill(self.buffer_info, 0, 0, 0, 0)
  if action.x and action.y then
	g = 10
	num = vmath.length(vmath.vector3(action.x, action.y, 0))/g
	dir = math.atan2(action.y, action.x)
	for i = 0, num do
		drawpixels.filled_circle(self.buffer_info, math.cos(dir)*i*g, math.sin(dir)*i*g, 5, 255, 255, 0, 255, true)
	end
  end
    resource.set_texture(go.get("/go#sprite", "texture0"), self.header, self.buffer_info.buffer)
end

3 Likes