Collision Shape
self:set_shape_mesh
SharedBuilds the collision shape from the meshes of a model
Syntax
local status = self:set_shape_mesh(
model,
config = {}
)Parameters
| Type | Name | Description |
|---|---|---|
model | model | Model instance whose meshes are used to generate the shape |
table | config | Optional generation settings Refer Config section |
Returns
| Type | Name | Description |
|---|---|---|
bool | status | true on successful generation, false if the model has no usable mesh |
Config
| Type | Key | Default | Description |
|---|---|---|---|
string | shape_type | "convex" | • When "convex" - builds a convex hull• When "concave" - builds an exact triangle mesh |
bool | include_children | false | Whether every matching mesh becomes its own child shape instead of one shape for the whole model |
table | filters | nil | List of {match, shape_type} rules, the first rule matching a component name overrides shape_type for it |
Examples
core.model.load("crate", "models/crate.glb")
local model = core.model.create("crate")
local body = physics.static.create()
local entity = physics.collision_shape.create(body)
entity:set_shape_mesh(model)core.model.load("crate", "models/crate.glb")
local model = core.model.create("crate")
local body = physics.static.create()
local entity = physics.collision_shape.create(body)
entity:set_shape_mesh(model, {
shape_type = "convex",
include_children = true,
filters = {
{match = "Floor*", shape_type = "concave"}
}
})