Close

Secrets of Godot

A project log for Silly software wishlist

Motivation to do some software projects by writing them down.

lion-mclionheadlion mclionhead 08/26/2018 at 00:150 Comments

MULTI STAGE ROCKETS IN GODOT

A better method is to use a single model when the rocket is 1 piece & 2 models after stage separation.  There's no practical way to dynamically attach 2 rigidbodies together.  It also makes it easier for the CG to go from a single point to 2 points.

Discovered double clicking icons in the scene graph centers the view on the nodes.  This doesn't work for nested meshes, of course.


SOUND NOTES

You can get sounds to play sequentially.   Given the AudioStreamPlayer sound

sound.connect('finished', self, 'playbackFinished')

connects the finished event to the playbackFinished function in the script.

func playbackFinished():

            sound.stream = samples[1]
            sound.play()

Then, the signal handler merely starts the next sample.  It seems pretty tight.

Making a sample play in a loop is accomplished thus:

    samples[1].loop_begin = 0
    samples[1].loop_end = 354211  # samples
    samples[1].loop_mode = AudioStreamSample.LOOP_FORWARD

There's no way to get the number of samples besides hard coding it.  A better way is to just replay it in playbackFinished.

PHYSICS NOTES

The VehicleBody demo uses very complicated calls to apply_impulse to get realistic driving behavior. Since apply_impulse applies the forces in the world domane, the 1st problem is rotating the forces to the domane of the vehicle.  This is done with rigid.transform.basis.orthonormalized() * Vector3(1, 0, 0)

where Vector3(1, 0, 0) is the force vector you want in the vehicle domane.  The rigid.transform.basis member is godot's way of extracting the rotation/scale matrix from the transform.  It has to be normalized by orthonormalized() to apply just rotation. Rigid.transform also has an origin member for extracting the translation.  The rotation matrix rotates both forces & torques into the vehicle domane.  Matrices are amazing things, if you forget about deriving them.



TURNING THE ROCKET

Turn objects by calling Rigidbody.apply_torque_impulse

The trick is making the turn stop when the joystick is centered.  The general idea is to apply rate damping feedback, the same as a quad copter.  Like a quad copter, there's a turn rate from a gyro in Rigidbody.get_angular_velocity().  This gives an angle per second you can apply to the object to dampen rotation, but apply_torque_impulse takes an instantaneous force, so the angular velocity has to be multiplied by the time difference since the last frame or the result is unstable.  

Despite this, the result of damping is very prone to explode.  It could be rounding errors in the physics engine.  The damping has to be exponential.

IMPORTING GLTF FILES

Discovered certain operations cause scenes derived from GLTF files to discard all the dependencies in the GLTF file.   Changes made to the GLTF file no longer show in Godot, once the dependencies are discarded.  The mane operation is converting a spatial to a rigidbody.  The easiest workaround is to import the new GLTF file into a temporary TSCN file, change the spatial to a rigidbody in the temporary file, quit Godot, open the TSCN files in a text editor, copy the changed meshes from the temporary TSCN file into the working TSCN file.  Perhaps a script could automate GLTF importing outside Godot.

The instant loss of dependencies is rough, since there's no undo & Godot prompts before quitting, regardless of if any files are unsaved.  Model creation is so brutally slow, this is all that came out of all those months of discoveries.  Since the real launchpad design is unknown, there's no incentive to make it more detailed.


Discussions