How to make like a little rope between two points using Immediate Mesh?

Godot Version 4.7

Question:

So i think the title already explains the question but i will go further. I want to make like a zipline that is procedurally generated, and just for the visual i would want for there to be like rope between two picked positions. So the question is more about how to make the visual rope, like, appear. For some insight i am a beginner programmer, so a simple code example would help.
The code that i already have for one end of the zipline:

extends StaticBody3D

@export var startPOS = self.global_position
@export var target = Node
@export var endPOS = Vector3()
func _ready() -> void:
    endPOS = target.global_position

You can learn how to do this through ImmediateMesh’s dedicated page in the documentation:

Additionally, you can check out ImmediateMesh’s class reference in the documentation.

The code will be slightly different depending on whether you want to build a flat 2D-style rope, or a more “accurate” cylindrical mesh. A cylindrical mesh is, arguably, more complex to build as a beginner because it requires a set of nested for loops. A “flat” rope is easier to procedurally generate, from a conceptual perspective, because you just need to align quads (2 triangles that form a square) along the AB vector (the vector that goes from your start point to your end point).

My advice would be the following:

  1. Start simple and build a flat rope consisting of quad-like geometry.
  2. Assign a material to the MeshInstance3D that disables backface culling so you can see both sides of the flat mesh.
  3. Once you have step 1 and 2 completed, you can start adding normals and UVs if you need it.

Focus on one thing at a time so you don’t bombard yourself with too many questions.


I implore you to check out the pages linked above and play around with it yourself. If there is something you can’t quite grasp, or you need further explanation about something, you are more than welcome to ask further questions in this post.