Skip to content

Physics

Weston McNamara edited this page May 2, 2021 · 4 revisions

Crynn has implemented rigidbody dynamics into the engine with the help of qu3e, a lightweight 3D physics engine.

Qu3e is very simple to use and easy to integrate so it made sense for this project. Because Crynn relies strictly on qu3e for physics, it inherits any limitations from that project. To know more about qu3e and its limitations, I recommend you take a look at their github repository.

Limitations

Physics in Crynn has a few limitations, partially due to both the Crynn engine and qu3e.

Current physics limitations in Crynn:

  • Only supports boxes (oriented and aligned axis) for collision.
  • You cannot get accurate rotation state information from an object simulated by a rigidbody. What does this mean? If an object is simulated with a rigidbody, the euler XYZ angles stored in the objects transform will not update based on rotation simulated by the rigidbody.

Using Rigidbodies

To create a rigidbody, you'll need to use the Rigidbody class.

Example:

Transform tr; //Stores position, rotation and scale data about an object. We will simulate this with Rigidbody physics.

//First parameter: body type. eDynamic is full rigidbody simulation. You can also use eKinematicBody and eStaticBody.
//Second parameter: a reference to the transform you want simulated.
//Third parameter: the bounding box to use as collision. Check Rigidbody.h for more info on this.
Rigidbody rb(eDynamicBody, tr, Box(Vec3(0, 0, 0), Vec3(1, 1, 1)));

//You can add more boxes with rb.AddBox()

Its that easy!

Important Advice

Because of the limitations in Crynn's rigidbody system, it is highly recommended that you only use the rigidbody dynamics system for simulating objects that do not need to be constantly kept track of, and of which the state you don't need to care about. What does this mean? Here are some examples.

DO use Rigidbodies in Crynn for:

  • Simulating objects blowing up in an explosion
  • Allowing props to fall off a table if the player bumps into them or shoots them
  • Having objects fall off a building
  • Simulating a soccer ball that moves if the player walks into it

DONT use Rigidbodies in Crynn for:

  • Simulating gravity and dynamics for your playable character
  • Creating a driveable car
  • Simulating an object that needs to be rotated in a specific way to complete a challenge

Why? Because as stated in the limitations, you cannot the track rotational state of rigidbodies. They are intended for things that dont really matter if you cant get the rotation of it, but still need physics to simulate them.