Successfully reported this slideshow.

Haroon alam

576 views

Published on

Published in: Technology, Art & Photos
  • Be the first to like this

Haroon alam

  1. 1. Physics, Rigidbody Simulation in Unity3D Syed Haroon Alam Pre Requisite: Basic understanding of game development, unity3d and scripting language
  2. 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
  3. 3. Components Built in physics components include: • Colliders • RigidBodies • Joints • Physics materials
  4. 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. 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. 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. 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. 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
  9. 9. Continuous vs Discrete collisions Frame - 1 Frame - 2 Frame - 3
  10. 10. Using continuous and continuous dynamic
  11. 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. 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. 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
  14. 14. Directional Friction
  15. 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. 16. Joints • Joint is a constraint that is defined between two Rigidbodies • Hinge Joint • Spring Joint • Fixed Joint • Configurable Joint
  17. 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
  18. 18. Raycasting • Shooting ray from specific direction • Use to check if collision is detected
  19. 19. Example Project
  20. 20. Upcoming Lectures • Wheel Colliders and Car Racing example game • Particle Systems • Rag dolls and Cloth Simulation
  21. 21. Assignment for next lecture – Make simple pool game
  22. 22. Famous Physics based mobile games Paper Toss Angry Birds Cut the Rope
  23. 23. Thank You Please feel free to drop me note at: syedharoonalam@gmail.com

×