Goodluck / API Reference

sys_physics_integrate

The first step of the physics simulation: integrate the rigid body's acceleration and velocity, and update the entity's transform.

For the physics simulation to work correctly, the following order of systems is recommended.

FixedUpdate(delta: number) {
    // Apply acceleration and velocity to position.
    sys_physics_integrate(this, delta);
    // Update transforms.
    sys_transform(this, delta);
    // Detect collisions.
    sys_collide(this, delta);
    // Optionally, derive the velocity of kinematic bodies.
    sys_physics_kinematic(this, delta);
    // Resolve collisions: move colliding bodies apart and swap velocities.
    sys_physics_resolve(this, delta);
    // Update transforms again to account for collision response.
    sys_transform(this, delta);
}

For deterministic results, the physics simulation should be run inside Game.FixedUpdate. Be careful about processing input inside FixedUpdate. It's OK to handle continuous input, like "is the key down for the duration of this update?". On the other hand, handling discrete input inside FixedUpdate, like "has the key been pressed during this update?" will lead to skipped input or input applied multiple times.