The Godot Community Forums are back up and running! Please read the the announcement post for important information on what happened. Thanks!

Create/alter shape of 3D colliders programmatically?

UnknownUserUnknownUser Posts: 0
edited August 31 in 3D

I'm quite new to godot. I see that the Collision Polygon class says it is editor-only, and changes made during gameplay will have no effect:

Is there an alternative to this for making 3D Colliders programmatically? For example, to programmatically generate many Box Colliders and alter their shape on-the-fly with a gdscript?


  • UnknownUserUnknownUser Posts: 0
    edited September 2

    Ah, I think I've found the/a solution. At least, for a BoxShape collider, this behaved as expected (i.e., by increasing SPEED, it causes the RigidBody to collide more quickly, and with more "empty space" where the MeshInstance doesn't cover it, with a StaticBody positioned beneath it):

    var SPEED = 1.0
    func _ready():
        self.shape.extents += 2.0 * Vector3(SPEED, SPEED, SPEED)
        print("extents: ", self, self.shape.extents)

    EDIT: And something similar works for a more general ConvexPolygon shape collider, lovely:

    func _ready():
        print("points: ", self.shape.points)
        for i in len(self.shape.points):
            self.shape.points[i] = 4.0 * self.shape.points[i]

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file