Immediate mesh problem

Godot Version 4.7

Question

So i’ve been trying to get my rope visual to work, like it got everything it should, but for some reason one side of it is just “shrank”, i can’t really figure out how to fix it.


i even did a little a little schematic to see if i placed the vertices correctly

Here’s the code for my rope thing (mostly copied from the immediate mesh documentation, except i changed it to fit in what i was doing):

extends MeshInstance3D

@export var start = Node
@export var target = Node
var endPOS = Vector3()
var startPOS = Vector3()

func _ready():
	endPOS = target.global_position
	startPOS = start.global_position
	mesh.surface_begin(Mesh.PRIMITIVE_TRIANGLES)

	# Prepare attributes for add_vertex.
	mesh.surface_set_normal(Vector3(0, 0, 1))
	mesh.surface_set_uv(Vector2(0, 0))
	# Call last for each vertex, adds the above attributes.
	mesh.surface_add_vertex(Vector3(startPOS.x, startPOS.y + 0.1, startPOS.z))

	mesh.surface_set_normal(Vector3(0, 0, 1))
	mesh.surface_set_uv(Vector2(0, 1))
	mesh.surface_add_vertex(Vector3(startPOS.x, startPOS.y - 0.1, startPOS.z))

	mesh.surface_set_normal(Vector3(0, 0, 1))
	mesh.surface_set_uv(Vector2(1, 1))
	mesh.surface_add_vertex(Vector3(endPOS.x, endPOS.y + 0.1, endPOS.z))

	# End drawing.
	mesh.surface_end()
	
	mesh.surface_begin(Mesh.PRIMITIVE_TRIANGLES)

	# Prepare attributes for add_vertex.
	mesh.surface_set_normal(Vector3(0, 0, -1))
	mesh.surface_set_uv(Vector2(0, 0))
	# Call last for each vertex, adds the above attributes.
	mesh.surface_add_vertex(Vector3(startPOS.x, startPOS.y - 0.1, startPOS.z))

	mesh.surface_set_normal(Vector3(0, 0, -1))
	mesh.surface_set_uv(Vector2(0, 1))
	mesh.surface_add_vertex(Vector3(endPOS.x, endPOS.y + 0.1, endPOS.z))

	mesh.surface_set_normal(Vector3(0, 0, -1))
	mesh.surface_set_uv(Vector2(-1, -1))
	mesh.surface_add_vertex(Vector3(endPOS.x, endPOS.y - 0.1, endPOS.z))

	# End drawing.
	mesh.surface_end()

Hi there!

Judging by your screenshot and drawing, you are missing the second half of that rope, the second triangle in your drawing.

I would pull out the vertexes and numbers into their own array for more readability.

Also maybe ask an LLM to check the numbers for you and see if the output corrects the visuals for you. They are usually quite good at that for such simple problems.

So the main problem turned out was backface culling, i disabled it. Made two meshes who are two separate triangles, and now everything is working correctly. Thank you for the help!