0 votes

I want a Trail3D to detect collisions, the trail is rendered on both sides and it's very similar to the trail from tron's lightcycles. I tried to instanciate Areas behind the player while it's moving, but it's not precise and having a lot of them causes lag.

Godot version 3.2.3 stable official
in Engine by (18 points)

You could probably use something like an ArrayMesh to draw the trails and use the createtrimeshcollision() function and update the vertex position every frame to create that effect

The node I'm using is a ImmediateGeometry node, to emit the trail it uses begin(Mesh.PRIMITIVETRIANGLESTRIP). I created a var trail = Mesh.PRIMITIVETRIANGLESTRIP and I tried to call createtrimeshcollision() but for some reason the variable is a int type...
How can I store the mesh into the variable? Or should I try something else?
EDIT: Ok, Mesh.PRIMITIVETRIANGLESTRIP is an enum, so I guess there's no way to make it work from this type of node

func _render_geometry(source: Array) -> void:
Base function for rendering the generated geometry to the screen.
Renders the trail, and the wireframe if set in parameters.
var points_count = source.size()
if points_count < 2:

# The following section is a hack to make orientation "view" work.
# but it may cause an artifact at the end of the trail.
# You can use transparency in the gradient to hide it for now.
var _d :Vector3 = source[0].transform.origin - source[1].transform.origin
var _t :Transform = source[0].transform
_t.origin = _t.origin + _d
var point = Point.new(_t, source[0].age)
var to_be_rendered = [point]+source
points_count += 1

var half_width :float = base_width/2.0
var wire_points = []
var u := 0.0

begin(trail, null)

This is not the entire script of course

I figured it out, I made my own script and it works fine.
I'll show the code for everyone who has the same project, the material culling must be disabled to render the trail and keep in mind that get_child(1) refers to the collision box.

extends MeshInstance

var target

var surfTool = SurfaceTool.new()
var material = SpatialMaterial.new()
var m = Mesh.new()
var p
var l = 0.1
var current_vertex = 0
var prev_point1 = Vector3.ZERO
var prev_point2 = Vector3.ZERO
var wr

var is_target = false

func set_target(t : KinematicBody):
target = t
p = target.global_transform.origin
prev_point1 = Vector3(p.x,p.y+l,p.z)
prev_point2 = Vector3(p.x,p.y-l,p.z)
wr = weakref(target)
is_target = true

func set_color(c: Color):
material.albedo_color = c
material.emission = c

func _ready():
material.vertex_color_use_as_albedo = true

func _process(delta):
if is_target:
    if wr.get_ref():
        p = target.global_transform.origin

    prev_point1 = Vector3(p.x,p.y+l,p.z)

    prev_point2 = Vector3(p.x,p.y-l,p.z)



    get_parent().get_child(1).shape = mesh.create_trimesh_shape()

Please log in or register to answer this question.

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.