0 votes

I have a (environment) scene with 77 mesh instance to which i want the player to be able to collide with.
Problem is, how do i automate the process of adding trimesh collision to each and every mesh.

Godot version 3.5
in Engine by (12 points)

1 Answer

0 votes

3 Steps .....

  1. Use tool mode
  2. Loop through SceneTree
  3. Create collisions

.

# Trimesh.gd
tool extends EditorScript

func _run():
    for child in get_scene().get_children():
        if child is MeshInstance:
            child.create_convex_collision()

The above code assumes a few things like all 77 MeshInstances are a child of the scene root which you can get over by creating a recursive function to get all nodes.

In the Script Editor press File > Run

by (6,932 points)
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.