Delay when using draw_line in update

Hello everyone! I’m making a game about fishing and I need to attach a fishing line to a hook. The hook is animated via go. animate and in the video you can see that there is a delay in drawing the line before diving into the water. Please tell me if it is possible to avoid this somehow?

msg.post("@render:", “draw_line”, {
start_point = go.get_position(“game:/line_start”),
end_point = go.get_world_position("/hook"),
color = line_color
})

1 Like

Hi @Alexander_Bulatov, nice, I like fishing games!

The draw_line message is meant to be used for debugging. You could use a sprite instead, with the anchor point at one end, then stretch the scale of it as needed.

Because the physics is moved after the update() function, you may also need to use this hack to be able to keep the sprite in sync with the physics objects:

local EMPTY_TABLE = {}
local VECTOR3_EMPTY = vmath.vector3()
local VECTOR3_ONE = vmath.vector3(1)

local function late_update()
	-- This update will happen after game objects have been moved by the physics engine
end

local function queue_late_update()
	physics.raycast_async(VECTOR3_EMPTY, VECTOR3_ONE, EMPTY_TABLE) 
end

function update(self, dt)
	queue_late_update() -- Hack to trigger ray_cast_missed after physics update.
end

function on_message(self, message_id, message, sender)
	if message_id == hash("ray_cast_missed") then
		late_update()
	end
end
4 Likes

Thanks. It would certainly be easier to draw a line from point A to point B, but apparently I will have to look for a solution with a pixel square.
UPD: I tryed your hack and it works pretty good!

This is most likely overkill for what you want to do, but it allows you to draw pixels:

There is no other way to draw geometry directly in Defold as far as I know.

1 Like

You can stretch a sprite between two points to draw lines.

LaserExample.zip (4.0 KB)

Also check out this example

2 Likes