Physics simulation in Unity involves applying real-world physics concepts using built-in components like rigidbodies, colliders, and joints. Colliders define collision shapes while rigidbodies make objects react to forces. Physics materials determine collision reactions. Raycasting shoots rays to detect collisions. Joints constrain rigidbody movement. The character controller handles players without rigidbodies. Upcoming topics include wheels, particles, ragdolls, and a pool game assignment.
The Codex of Business Writing Software for Real-World Solutions 2.pptx
Haroon alam
1. Physics, Rigidbody Simulation in
Unity3D
Syed Haroon Alam
Pre Requisite:
Basic understanding of game development,
unity3d and scripting language
2. Introduction
• Physics in Game Development: Involves the laws
of physics into a game engine for the purpose of making
effects more real to the observer
• Game Physics in Unity3D: Built in physics library and
components to produce results in real-time that replicate
real world physics
Physics engines used in unity:
• NVIDIA PhysX Physics engine - 3D game development
• Box2D physics system - 2D game development
4. Colliders
• Colliders are used to define the collision shape of
objects in your scene
• Unity primitive colliders: Box, Sphere and Capsule
• Mesh Collider can be used for complex meshes
• Wheel Collider component for vehicles
• Terrain Collider component for terrains.
5. • A concave polygon always have an interior angle
with a measure that is greater than 180 degrees
• A convex polygon has internal angle is less than
or equal to 180 degrees. Every line segment
between two vertices remains inside or on the
boundary of the polygon.
6. Trigger Colliders
• Colliders can be used as a Trigger by setting
the Is Trigger property to true
• Not participate in collision simulations
• Fire OnTriggerEnter, OnTriggerStay, and
OnTriggerExit events
7. Rigidbodies
• Used For objects to act under the influence of
Physics.
• Forces and torques to the Rigidbody component
can be applied from scripts
• Requires a Collider component to be present on
the GameObject for correct Physics simulation
• Can be Physics controlled or Kinematic controlled
8. Rigidbodies
Collision Detection
• Discrete:
- Uses Discreet collision detection against all other colliders in the scene.
- Skips detection when an object is on one side of a collider in one frame, and
already passed the collider in the next frame
• Continuous:
- Uses Continuous Collision Detection against colliders with no rigidbody
- Uses CCD against rigidbodies set to Continuous Dynamic
- User Discrete collision detection for all other colliders
• Continuous Dynamic:
- Uses CCD on rigidbodies that are either set to Continuous or Continuous
Dynamic and colliders with no rigidbody
- Use only for fast moving objects
- User Discrete collision detection for all other colliders
11. Moving rigidbodies
• If isKinematic is enabled, the object will not be driven by
the physics engine, and can only be manipulated by its
Transform
• FixedUpdate() should be used instead of Update() when
dealing with Rigidbody
• rigidbody.MovePosition
• rigidbody.AddForce
• rigidbody.AddTorque
12. Rigidbody Colliders
• Colliders that also have a Rigidbody will react
to collisions
• Contains information about contact points,
impact velocity, rigidbody and collider
• Fire OnCollisionEnter(), OnCollisionStay(), and
OnCollisionExit() events
13. Physics Material
• Reaction of physically controlled objects on
each other.
• Used to get desired physical behavior on
collisions
• Unity provides a few default Physic Materials
15. Character Controller
• Used on characters i.e for third-person or first-person
player control
• Does not require a Rigidbody
• Does not react to forces on its own and it does not
automatically push Rigidbodies away
• Character Controller colliding with non-static Rigidbodies
must be done via script
• Events: OnControllerColliderHit()
16. Joints
• Joint is a constraint that is defined between
two Rigidbodies
• Hinge Joint
• Spring Joint
• Fixed Joint
• Configurable Joint
17. Joints
• To constrain one Rigidbody to another along a
particular axis
• Spring Joint can be used to create an invisible spring
that tries to keep two rigid bodies together.
• Fixed Joint can be used to keep two Rigidbody objects
together at a constant distance and orientation.
• Configurable Joint allows you to create complex joint
configuration