Ok I'm noob and I can't fix the code myself. I created a timer for the generation of the vertexes, it has to be 0.017 seconds or less, or the trail is not rendered precisely.
A second timer creates the collision box every 0.07 seconds, it does improve performance if i increase the time, but i need the collisions to exist as soon as possible.
This is the code:
func _on_Timer_timeout():
if is_target and wr.get_ref():
surfTool.begin(Mesh.PRIMITIVE_TRIANGLES)
surfTool.add_vertex(prev_point1)
surfTool.add_vertex(prev_point2)
surfTool.add_vertex(Vector3(p.x,p.y+l,p.z))
prev_point1 = Vector3(p.x,p.y+l,p.z)
surfTool.add_vertex(Vector3(p.x,p.y-l,p.z))
prev_point2 = Vector3(p.x,p.y-l,p.z)
surfTool.add_index(0)
surfTool.add_index(1)
surfTool.add_index(2)
surfTool.add_index(1)
surfTool.add_index(2)
surfTool.add_index(3)
surfTool.index()
surfTool.commit(m)
set_mesh(m)
else:
get_parent().queue_free()
func _on_Refresh_timeout():
get_parent().get_child(1).shape = mesh.create_trimesh_shape()