Physics
Physics
Physics include the movement and collision of objects, which typically require 2 components: a physics component and a collider. Lumberyard is in the transition between CryPhysics and PhysX, because the project was started with version 1.12 our experience mainly involves the legacy system. The simulation of physics can happen in 2 ways, while the game is running as well as simulating it through the Perspective Viewport toolbar, see Perspective Viewport for more information.
Legacy Physics System
Lumberyard’s physics system offers simulation of physical systems, including static and dynamic physical entities, triggers and collisions, ragdoll, and more advanced systems such as hair, particles, wind, and water. The AI/Phyiscs button in the bottom bar of the Perspective Viewport is a useful tool to simulate the two systems without needing to enter into the game mode.
Static Physics
The static physics component is applied to bodies that have logically “infinite mass”. That means that while they can other entities can have physics interactions with them, they are stationary and immovable themselves. Usually, things like a wall would have a static physics component since while they let other entities collide with it, they don’t move themselves.
Rigid Body Physics
Rigid Body Physics is usually added to non-living entities that you want to be able to interact with the physics system and also respond to it. Any living entity should generally have Character Physics rather than Rigid Body Physics, and an entity can only have one of these components, but not both. Rigid Bodies are generally dynamic, in the sense that they can apply or react to forces and collisions.
Colliders
In addition to Static or Rigid Body Physics components, entities require some kind of collider also attached to them. While the physics components are responsible for simulating physics, colliders actually record collisions that in turn invoke corresponding physics simulations. A collider can be Primitive (which requires a Shape component for the primitive shape you want your collider to be as), or Mesh (takes the shape of the required Mesh component attached to the entity).
Primitive shape colliders are associated with a shape, and the shapes are attached at the center of the entity. Shapes dimensions can be scaled however not not offset from the entity’s pivot. All shapes don’t work with the primitive collider component, only the primitives so not the polygon prism shape, compound shape or spline.
There is a visual bug associated with shape colliders and scaling. If an entity’s transform is scaled then the shape will be scaled with the largest scaled axis, ie if the entity is scaled Vec3(2,1,1) then the box will appear with dimensions Vec3(2,2,2). However, the primitive collider isn’t actually of size Vec3(2,2,2) rather still the original size of Vec3(1,1,1). The image below demonstrates this, the left entity is scaled by 2 in the x dimension but has the same collider size as the right entity.
For a mesh collider to act as an active component on an entity, there must be a mesh component attached to the entity and that mesh must have physics proxy associated with it. Where primitive colliders show the shape, although sometimes inaccurate, the mesh collider don’t show any visual information in the level editor. This can be particularly deceiving when an entity is scaled to know the collider has an accurate shape, as well as determining whether the mesh’s physics proxy is exists and will work as a collider.
Physics Proxies
Any mesh, not rigged actor, that will use a mesh collider needs physics proxies generated for the asset. These are geometries that are needed for collision detection. Opening up any mesh from the Asset Browser lets you add a Physics Proxy modifier to it that can then be used by any physics components attached on an entity of the same mesh. Physics will not work if the mesh does not have a proxy added to it. While adding proxies was a painless procedure in v1.12, v1.13 caused an irreparable issue in our copies of the engine where updating a mesh after adding the proxy would fail without a good explanation. The workaround to this was to copy the fbx asset to v1.12, build the mesh with the proxy (updating the assetinfo), and finally copying the fbx asset, assetinfo and material file that were generated in v1.12 back to the project in v1.13.
Character Physics
Character Physics allows adding physical behavior to character entities. This is mainly used on game characters like players on enemies. It’s different from the rigid body physics system since these entities can actually be “moved physically” in correspondence with the AI and Animation systems. Without a character physics component, the entity’s animations won’t be able to move the entity in the level. One of the main drawbacks of Character Physics is that the collider fields in the component are vaguely defined, and since the collider is not visible to us at all, setting the values becomes a painful trial-and-error task.
Character Physics component allows masking out of different types of physical entities that the character itself can interact with.
The entity pictured below has a character physics component attached to it. Like a mesh collider, there is no visual information in the level editor to tell the shape or size of the collider. This is more concerning than a mesh collider, because the character physics component allows for the player dimensions to be specified but there is no feedback of what the changes are doing until play mode/simulation.
Ragdoll Physics
Ragdoll physics doesn’t work with the new FBX workflow.
PhysX
Lumberyard offered physics for games through its legacy physics system until version 1.12. In the latest version (1.13), PhysX was released in preview mode that would in the future replace the legacy system. However, at it’s current state, PhysX doesn’t offer all the features of the legacy system, such as interaction with Character Physics, and both the physics systems don’t interact with each other. This makes it hard to either entirely switch to PhysX or to use both simultaneously. PhysX still needs to mature until it can be adapted in place of the legacy physics system, however, you can use the resources provided below to learn more about PhysX.