#Problem with drawing 3D line from Immidiate Mesh in Godot 4

2 messages · Page 1 of 1 (latest)

wooden meadow
#

I have a problem with drawing a line from two points, one point being a roaming enemy ai and the other the fpsplayer,
get_parent().global_transform.origin is the enemy the immideate mesh is attached to and globals.playerpos is the global transform.origin of the player.
what actually happens is that the line has an offset and rotates when the parent is moved, but not in an expected way

in the picture the line should normaly be drawn from the player so in this case from high up since its an FPS character controller and should end at the enemy ai


func draw_line(begin_pos: Vector3, end_pos: Vector3, color: Color = Color.RED) -> void:
    mesh.clear_surfaces()
    mesh.surface_begin(Mesh.PRIMITIVE_LINES)
    mesh.surface_set_color(color)
    mesh.surface_add_vertex(begin_pos)
    mesh.surface_add_vertex(end_pos)
    mesh.surface_end()

func _process(delta):
    draw_line(get_parent().global_transform.origin, Globals.playerPos, Color(1,1,1,1))```
#

the green thing is the enemy