Adding collisions to meshes
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
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
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.