Adding collisions to meshes
Basic collider
Section titled “Basic collider”There are a few occassions when you might want a simple collision but usually you’ll need to structure your object with a hierarchy like below in the #Dynamic-collider section. Let’s imagine you do actually want a simple sphere to act as a collider. You would create the following hierarchy in your Blender object:
MyBall (Empty)├── BallMesh (Detailed sphere if you need one)└── PhysicsSphere (Simple sphere mesh) └── Custom Properties: node = "rigidbody" type = "dynamic" node = "collider" convex = true
To set the custom properties you select your mesh (simple sphere in this example) and scroll down to the bottom and add a new custom property like this:
- click OK and then set the value to ‘collider’ so it looks like this:
If you want to create a fancy ball (eg one with football panels/decals etc.) you’d add that as a sibling of PhysicsSphere so that it isn’t used in the physics calculations.
For anything more complicated that this you will want to separate the collision and rigidbody meshes as shown in the next section.
Dynamic collider
Section titled “Dynamic collider”To create a collider that responds to physics you need to create an object with the following structure:
MyDynamicObject (Empty/Group)├── DetailedMesh (Complex mesh - what the thing looks like)└── rigidbody (Empty or minimal mesh) └── Custom Properties: node = "rigidbody" type = "static" | "kinematic" | "dynamic" mass = [number value >= 0] (see note below) tag = [optional string, cannot be "player"] └── CollisionShape (Simplified collision mesh) └── Custom Properties: node = "collider" convex = [true/false]
Note: mass is not currently supported so just leave it out - it will be set to a default of 1.
rigidbody types
Section titled “rigidbody types”Looking at the RigidBody.js code, there are three types defined:
const types = ['static', 'kinematic', 'dynamic']
Here’s what each does:
-
static
- For immovable objects like walls, floors, or fixed furniture. The code shows these create acreateRigidStatic
PhysX actor which:- Won’t move when hit
- Other objects will collide with it
- Most efficient performance-wise
-
dynamic
- For objects that should move realistically with physics. Creates acreateRigidDynamic
PhysX actor that:- Will respond to gravity
- Will bounce/collide with other objects
- Will be pushed by forces
- Uses the mass property for physics calculations
-
kinematic
- For objects that move but aren’t affected by physics. Also creates acreateRigidDynamic
actor but sets theKINEMATIC
flag:- Can be moved programmatically
- Other objects will collide with it
- Won’t respond to gravity or forces
- Mass is less important since it’s not physics-driven
So for your example - if you want the object to fall and bounce realistically, use type="dynamic"
. If it should stay perfectly still, use type="static"
. Use kinematic
if you want to move it programmatically but still have other objects collide with it.