Close

Godot physics secrets

A project log for A game about a certain space exploration company

Where most of 2018 went

lion mclionheadlion mclionhead 04/09/2020 at 06:330 Comments

The general idea is the top level physics object is a rigidbody or a staticbody.  The rigidbodies move & the staticbodies are stationary.  The rigidbody itself doesn't interact with anything but gravity.  It has a bunch of collisionshape children which define the shape which interacts with other objects.  The collisionshapes are just meshes.  The collisionshapes are held in the same relative positions by the rigidbody, like a real solid.  The collisionshape geometry determines if the rigidbody rolls over, stands upright, behaves like a ski, a wheel, a leg, or gets stuck.

The rigidbody contains physics parameters which apply to all the collisionshapes, so all the collisionshapes need to have the same mass.  Each collisionshape has a shape variable which points to its mesh.  The shape member can be created by the shape menu, importing a -col object from blender, or assigning the shape variable in gdscript.


The rigidbody has a center of gravity defined by its pivot point.  The CG determines if it's self righting or constantly rolls over.  There is no way to set the pivot point like there is in blender.  All the collisionshapes & meshes in the rigidbody need to be individually repositioned to change the CG.  To simplify matters, a model should have spatial as its top node, a rigidbody directly under that, & a single child node under the rigidbody containing all the visual meshes & collisionshapes.  This allows the model to have an arbitrary pivot point for placement in the scene, its CG can be a different pivot point, & its meshes can be another pivot point.

Helas, only spatials can be grouped inside another node.  The collisionshapes have to be directly inside the rigidbody & all moved individually.  At least you can shift select all the rigidbodies & move them at once.

Godot menus confused the hell out of lions.  When a godot menu item says "new...", "new BoxShape" or "new SpatialMaterial", it doesn't create multiple objects or leak memory like new in C++.  It just replaces whatever object was already there.  The menu title causes the options for the current object to be displayed.  The down arrow allows different objects to be created.

Your biggest ally in the war on Godot is the "expand all properties" menu item.

Getting back to rigidbody,

rigidbody.sleeping

rigidbody.can_sleep

These have to be off until liftoff, to keep players from falling uncontrollably to the launchpads & falling over.

rigidbody.physics_material_override

Create one of these to set more properties.

PhysicsMaterial.bounce

How much the object bounces.

PhysicsMaterial.absorbent

Seems to turn off all bouncing.  Now, it just gets stuck when it hits the wall.  

A big problem is the global_transform is required for calculating look_at angles & gravity vectors, but it's only available in the _process function.  Procedurally generated models have to be created in the _ready function, but anything requiring global_transform has to be done in _process.  The distributive property doesn't apply when multiplying transforms by vectors, either.



Discussions