Unity3D Physics April 3, 2015 Comp Game Design Michael Shah
Physics Topics ●Physics Games o Couple studies of physics gone well ●Physics as the main mechanic o Case study of games ●Unity3D Physics o Tweaking Physics ●Physics Engines o Further items to look at (and appreciate physics)
Realistic Physics ●Goal is to simulate the real world as close as possible.
Realism on a sliding Scale ●Trials HD ●Tony Hawk Pro Skater
Cartoon Physics ●Angry Birds ●Flappy Bird ●Mario
Another reason to Love Unity
Physics as A Mechanic ●Half-Life 2 Gravity Gun ●Portal
Why we need good Physics (This game was probably never tested!)
Unity Physics - The Basics ●Built on top of Nvidia’s PhysX System ●Lets look at the built in components
Colliders ●Box, Sphere, Capsule, and Mesh o OnCollisionEnter, OnCollisionExit, OnCollisionStay ●Colliders as Triggers o OnTriggerEnter, OnTriggerExit, OnTriggerStay ● Detecting a Collision requires at least one of the colliding objects to have a: void OnCollisionEnter(Collider col) method.
Mesh Collider Example
Rigid Body ●Used for moving objects ●Gameobject is effected by Gravity
Force and Torque ●Add Force o Change movement of object ●Add Torque o Rotate object around axis.
Physic Materials ●Physics Materials effect the way the object reacts in the game engine (Basketball versus bowling bowls surface). o Dynamic friction: Effects the object as it moves. o Static Friction: How much force is needed to move an object from a static position (sticky glue-like). o Bounciness: self-explanatory o Friction and Bounce Combine: How to respond to another object during collision.
Joints ●Fixed o Does not move until break force exceeded ●Spring o Hooke’s Law ●Hinge o Doors
Raycasting ●Raycasting: The process of shooting an invisible ray from a point to a specified direction into any colliders. o Use Debug.DrawRay to see where you are casting a ray
Raycast Against Specific GameObjects
Puzzles ●Some Exercises to walk through o How would you implement the scene? o What types of objects would you construct? What does the hierarchy look like?
Puzzle #1 - Destructible Wall
Puzzle #2 - Wrecking Ball
Puzzle #3 - Trampoline bouncy-spring-please-help.53181/
Puzzle #4 - Pool of Water
Puzzle #5 - Ragdoll
Puzzle #6 - Destructible Objects
Puzzle #7 - Improve Performance of Complicated Geometry mediate/physics/physics-best-practices
Answer - Physics Manager
Best Practices ●Remember that 2D is different than 3D in Unity o All of those puzzles, the same features apply, but use the 2D components! ● working-with-unity-best-practices/ working-with-unity-best-practices/ o 9. Put your world floor at y = 0. This makes it easier to put objects on the floor, and treat the world as a 2D space (when appropriate) for game logic, AI, and physics.
Physics in Regards to Lighting
Physics in Regards to Animation ●Integrate Maya into the pipeline ●‘Apply Root Motion’ powers animated objects based on animation o No need to move Transform or add Force
A nimation as an Agent-Based System ●Flocking Behavior o Physics - Attract and Repel Objects o ● Crowd Simulation ●Particle System
Appreciating the built-in Physics Three Books to build your own physics engine