# Physical system

# introduction

Use the physics system to add physical effects to the 3D objects in the scene, so that they can move, rotate, and collide in accordance with the laws of physics.

Nvidia PhysX is integrated in the frame of the mini game, and it adopts a simple and easy-to-use componentized design. Allow users to quickly get started with minimal cost, and easily add realistic and high-performance physical effects to the game.

In the game script, you can get the global instance of the physics system through game.physicsSystem.

//TODO should put a cover image

# Get started quickly

Click Download physical performance demo to experience it directly in the tool.

Click Download Tool Novice Guide, and learn directly in the tool according to the process.

You can also click here to learn how to make the cube in the scene become a rigid body in the physical world and fall on the floor.

# Physical simulation

The physics system collects objects with physical components in the scene, and performs physics simulation on them at the very beginning of each frame (prior to scripting and rendering).

In the process of physical simulation, the rigid body with speed will move forward, and may be affected by gravity, friction, damping, etc. and cause acceleration; collision bodies (or Triggers) will collide with each other, changing their Movement state, and generate physical events.

The duration of each physical simulation is fixed. Generally speaking, it will be less than the duration of the rendering frame. The default is 0.02s, which can be changed by PhysicsSystem.fixedDeltaTime. There may be multiple timesphysical simulations in one frame, depending on the duration of the rendered frame.

After each physical simulation, a physical event will be generated first, and then the onFixedUpdate function in the user script will be called once.

# Physical components

  • Rigidbody: Rigid body component, which allows the object to be displaced or rotated in the physical simulation stage;
  • Collider: Collider component, which describes the shape of the object so that it can collide;
  • CharacterController: A physical character controller component, which can simulate a character moving in a world full of obstacles.
  • Joints: Joint components, you can use various methods to connect a rigid body and another rigid body (or spatial position) to limit the movement and rotation of the rigid body.

# Physical Resources

  • PhysicMaterial: Modify the physical material of the collision body surface.

# Physics tool functions

The global physics tool functions are mounted on the game.physicsSystem.

  • # X-ray inspection

    You can manually project a ray (or other shape) to the scene to detect physical collision objects that intersect the ray. For details, see rayCast,boxCast,overlapBox, etc. in the API documentation.

  • # Physics Collision Matrix

    You can set some Layer to avoid physical collision by setting physical collision.

    In the ProjectSetting tab in the tool, you can manually set the collision matrix.

    You can also call PhysicsSystem.ignoreLayerCollision in the script to set certain two layers not to collide.