0 votes

Hello dear community!

I've been told many times that the godot editor was implemented purely in godot. I have recently begun working with VR a bit and tried to implement my own teleportation with a technique i found that is called tall ray casting. I have been able to sucessfully implement the feature however i am missing a proper visualization for where I am teleporting.

Having tried multiple different approaches that all looked quite performance-heavy, i started wondering how the 2D visualization of a Path3D in the editor actually works as it looks promissingly performance-light. Can someone explain to me how i could render a simple line like this in 3D?

Edit: I should probably note that i would require a bezier line, not just a simple "raycast".

asked Mar 2 in Engine by Toothgapsy (26 points)

1 Answer

+1 vote
Best answer

You could try using the ImmediateGeometry node, which allows you to draw lines from script in real time: https://docs.godotengine.org/en/stable/classes/class_immediategeometry.html

answered Mar 2 by Zylann (26,045 points)
selected Mar 4 by Toothgapsy

Does it support bezier behaviour somehow? Looking into the docs I have not found anything like that. I really wonder how the godot editor implements the visualization.

It just draws lines, really.
Bezier is not something you will find in the drawing methods themselves, it's rather the data you are using to draw such lines.

The Path3D node can look curvy because it uses a Curve3D resource, which can provide bezier positions by interpolating its points.
So if you want to draw bezier curves, you need to use a Curve3D resource, add points to it, define its control points, and use interpolate_baked(), or tessellate() to obtain points along the curve: https://docs.godotengine.org/en/stable/classes/class_curve3d.html

Now to draw it, all you need is to draw a line between each of the points you obtained.
Here is how Godot does it: https://github.com/godotengine/godot/blob/80582ffa662bb4dea223003856320ede37365603/editor/plugins/path_editor_plugin.cpp#L228
It uses a Gizmo API which generates a mesh behind the scenes, but you can also do it with ImmediateGeometry, SurfaceTool or ArrayMesh.add_surface_from_arrays.

Just figured that out myself yesterday. Thank you, functioning just as needed :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.