Unity 3 D Physics April 3 2015 Comp

  • Slides: 32
Download presentation
Unity 3 D Physics April 3, 2015 Comp 150 - Game Design Michael Shah

Unity 3 D Physics April 3, 2015 Comp 150 - Game Design Michael Shah

Physics Topics ● Physics Games o Couple studies of physics gone well ● Physics

Physics Topics ● Physics Games o Couple studies of physics gone well ● Physics as the main mechanic o Case study of games ● Unity 3 D 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.

Realistic Physics ● Goal is to simulate the real world as close as possible.

Realism on a sliding Scale ● Trials HD ● Tony Hawk Pro Skater

Realism on a sliding Scale ● Trials HD ● Tony Hawk Pro Skater

Cartoon Physics ● Angry Birds ● Flappy Bird ● Mario

Cartoon Physics ● Angry Birds ● Flappy Bird ● Mario

Another reason to Love Unity

Another reason to Love Unity

Physics as A Mechanic ● Half-Life 2 Gravity Gun ● Portal

Physics as A Mechanic ● Half-Life 2 Gravity Gun ● Portal

Why we need good Physics https: //youtu. be/NYt 3 B 9 lc. Um 0?

Why we need good Physics https: //youtu. be/NYt 3 B 9 lc. Um 0? t=4 m 49 s (This game was probably never tested!)

Unity Physics - The Basics ● Built on top of Nvidia’s Phys. X System

Unity Physics - The Basics ● Built on top of Nvidia’s Phys. X System ● Lets look at the built in components

Colliders ● Box, Sphere, Capsule, and Mesh o On. Collision. Enter, On. Collision. Exit,

Colliders ● Box, Sphere, Capsule, and Mesh o On. Collision. Enter, On. Collision. Exit, On. Collision. Stay ● Colliders as Triggers ● On. Trigger. Enter, On. Trigger. Exit, On. Trigger. Stay Detecting a Collision requires at least one of the colliding objects to have a: void On. Collision. Enter(Collider col) method. o

Mesh Collider Example

Mesh Collider Example

Mesh Collider Example

Mesh Collider Example

Rigid Body ● Used for moving objects ● Gameobject is effected by Gravity

Rigid Body ● Used for moving objects ● Gameobject is effected by Gravity

Force and Torque ● Add Force o Change movement of object ● Add Torque

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

Physic Materials ● Physics Materials effect the way the object reacts in the game engine (Basketball versus bowling bowls surface). 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. o

Joints ● Fixed o Does not move until break force exceeded ● Spring o

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

Raycasting ● Raycasting: The process of shooting an invisible ray from a point to a specified direction into any colliders. o Use Debug. Draw. Ray to see where you are casting a ray

Raycast Against Specific Game. Objects

Raycast Against Specific Game. Objects

Puzzles ● Some Exercises to walk through o o How would you implement the

Puzzles ● Some Exercises to walk through o o How would you implement the scene? What types of objects would you construct? § What does the hierarchy look like?

Puzzle #1 - Destructible Wall https: //www. youtube. com/watch? v=Ij. ELu_Q 01 e. Q

Puzzle #1 - Destructible Wall https: //www. youtube. com/watch? v=Ij. ELu_Q 01 e. Q

Puzzle #2 - Wrecking Ball https: //www. youtube. com/watch? v=o. AWGs 0 kt_v. M

Puzzle #2 - Wrecking Ball https: //www. youtube. com/watch? v=o. AWGs 0 kt_v. M

Puzzle #3 - Trampoline http: //forum. unity 3 d. com/threads/trampolinebouncy-spring-please-help. 53181/

Puzzle #3 - Trampoline http: //forum. unity 3 d. com/threads/trampolinebouncy-spring-please-help. 53181/

Puzzle #4 - Pool of Water https: //www. youtube. com/watch? v=m. Dtn. T 5

Puzzle #4 - Pool of Water https: //www. youtube. com/watch? v=m. Dtn. T 5 fh 7 Ek

Puzzle #5 - Ragdoll

Puzzle #5 - Ragdoll

Puzzle #6 - Destructible Objects https: //www. youtube. com/watch? v=IXl. A 3 HSIDPg

Puzzle #6 - Destructible Objects https: //www. youtube. com/watch? v=IXl. A 3 HSIDPg

Puzzle #7 - Improve Performance of Complicated Geometry http: //unity 3 d. com/learn/tutorials/modules/inter mediate/physics-best-practices

Puzzle #7 - Improve Performance of Complicated Geometry http: //unity 3 d. com/learn/tutorials/modules/inter mediate/physics-best-practices

Answer - Physics Manager

Answer - Physics Manager

Best Practices ● Remember that 2 D is different than 3 D in Unity

Best Practices ● Remember that 2 D is different than 3 D in Unity o All of those puzzles, the same features apply, but use the 2 D components! ● http: //devmag. org. za/2012/07/12/50 -tips-forworking-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 2 D space (when appropriate) for game logic, AI, and physics.

Physics in Regards to Lighting

Physics in Regards to Lighting

Physics in Regards to Animation ● Integrate Maya into the pipeline ● ‘Apply Root

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

Animation as an Agent-Based System ● Flocking Behavior o o Physics - Attract and

Animation as an Agent-Based System ● Flocking Behavior o o Physics - Attract and Repel Objects https: //www. youtube. com/watch? v=EZEK 1 l. Xx. Ff. A Crowd Simulation ● Particle System ●

Appreciating the built-in Physics Three Books to build your own physics engine

Appreciating the built-in Physics Three Books to build your own physics engine