Haroon alam
-
Upload
syed-alam -
Category
Technology
-
view
188 -
download
2
description
Transcript of Haroon alam
![Page 1: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/1.jpg)
Physics, Rigidbody Simulation in Unity3D
Syed Haroon Alam
Pre Requisite:Basic understanding of game development, unity3d and scripting language
![Page 2: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/2.jpg)
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
![Page 3: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/3.jpg)
Components
Built in physics components include:
• Colliders
• RigidBodies
• Joints • Physics materials
![Page 4: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/4.jpg)
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.
![Page 5: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/5.jpg)
• 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.
![Page 6: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/6.jpg)
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
![Page 7: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/7.jpg)
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
![Page 8: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/8.jpg)
RigidbodiesCollision 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
![Page 9: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/9.jpg)
Continuous vs Discrete collisionsFrame - 1 Frame - 2 Frame - 3
![Page 10: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/10.jpg)
Using continuous and continuous dynamic
![Page 11: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/11.jpg)
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
![Page 12: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/12.jpg)
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
![Page 13: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/13.jpg)
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
![Page 14: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/14.jpg)
Directional Friction
![Page 15: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/15.jpg)
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()
![Page 16: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/16.jpg)
Joints
• Joint is a constraint that is defined between two Rigidbodies
• Hinge Joint• Spring Joint• Fixed Joint• Configurable Joint
![Page 17: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/17.jpg)
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
![Page 18: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/18.jpg)
Raycasting
• Shooting ray from specific direction• Use to check if collision is detected
![Page 19: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/19.jpg)
Example Project
![Page 20: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/20.jpg)
Upcoming Lectures
• Wheel Colliders and Car Racing example game• Particle Systems• Rag dolls and Cloth Simulation
![Page 21: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/21.jpg)
Assignment for next lecture – Make simple pool game
![Page 22: Haroon alam](https://reader034.fdocuments.net/reader034/viewer/2022050808/547ec0d55906b59c718b46ed/html5/thumbnails/22.jpg)
Famous Physics based mobile gamesPaper Toss Angry Birds
Cut the Rope