+ All Categories
Home > Documents > CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf ·...

CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf ·...

Date post: 20-Aug-2018
Category:
Upload: doandien
View: 215 times
Download: 0 times
Share this document with a friend
17
CS248 Lecture 10 February 9 th , 2017 S IMULATION ( AND OTHER STUFF ) IN U NITY
Transcript
Page 1: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

CS248 Lecture 10

February 9th, 2017

S IMULAT ION ( AND OTHER STUFF ) I N UNI T Y

Page 2: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Overview§ Physics

› Rigid Body› Wheels› Cloth› Fracture (not covered in live demo)

§ Particle Systems§ Navigation (not covered in live demo)

Page 3: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Physics

J U S T C A U S E 2 4 8

Page 4: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Rigid Body

Stereotypical Barrel Drop Physics Test (UE3)

Page 5: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Rigid Body

Cow Boosting (Just Cause 3)

Page 6: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Rigid Body§ Use Unity Rigid Bodies (http://docs.unity3d.com/ScriptReference/Rigidbody.html)

› Your GameObject should have some collider attached (box, capsule, mesh, sphere, etc.)› Give it a PhysicMaterial (http://docs.unity3d.com/Manual/class-PhysicMaterial.html) to change

how rigid bodies interact.§ How to move your rigid bodies? With forces! (Don’t forget: 𝐹 = 𝑚𝑎 )

› Constant Force: http://docs.unity3d.com/Manual/class-ConstantForce.html› RigidBody also has ‘AddForce/Torque’ functions:

• AddForce: http://docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html• AddForceAtPosition:

http://docs.unity3d.com/ScriptReference/Rigidbody.AddForceAtPosition.html• AddExplosionForce:

http://docs.unity3d.com/ScriptReference/Rigidbody.AddExplosionForce.html (because what good is physics if you can’t do explosions)

§ Don’t use the C++ plugin rigid bodies (unless you really, really, really want to).

Page 7: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Rigid Body Constraints§ Use Unity joints (character joints, fixed joints, hinge joints, etc.).

Euphoria Engine Ragdoll

Page 8: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Wheels§ Use wheel collider: http://docs.unity3d.com/Manual/class-WheelCollider.html§ You can now move your vehicle by applying forces (or braking) to your wheels

Need For Speed 2015 Racing

Page 9: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Cloth§ Use Unity’s provided cloth component: http://docs.unity3d.com/Manual/class-Cloth.html§ Your cloth won’t be perfect – it will intersect with things in the world and that’s okay.

Assassin’s Creed Unity Cloth

Page 10: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Fracture§ Unity does not come with a built-in fracture system (UE4 does). Plugins exist (mainly non-free ones).§ But the concept is fairly simple (implementation not so much):

› Start off with a static mesh (i.e. a pillar).› Upon hitting the mesh with a force (i.e. with a ball), split the entire mesh (or just part of the mesh)

using an algorithm (pre-generated or on the spot).• “Real Time Dynamic Fracture with Volumetric Approximate Convex Decompositions” -

http://matthias-mueller-fischer.ch/publications/fractureSG2013.pdf› Apply forces to the fractured mesh pieces as necessary (i.e using the rigid body techniques from

earlier)

Battlefield 4 Levolution

Page 11: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Particle SystemsW H A T G O O D A R E

E X P L O S I O N S I F T H E Y ’ R E N O T

P R E T T Y

Page 12: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Particle Systems

Metal Gear Solid 5 Explosion

Page 13: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Particle Systems

Counter Strike Global Offensive Muzzle Flash

Page 14: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Particle Systems§ Particle systems transform according to rules that you give it:

› Initial velocity, velocity over time, size over time, etc.› You also control number of particles to spawn, when they spawn, when they stop spawning,

etc.§ Particle system is just a bunch of points moving in space.§ Rendered using textures (each particle gets the same texture).

› Can use a texture atlas to give particle system the illusion of changing over time (i.e. going from fire to smoke).

§ Free particle textures available on the asset store (you will probably find it hard to make your own)!

Page 15: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

NavigationU S U A L L Y E A S I E R

T H A N D R A W I N G P A T H S

Page 16: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

NavMesh§ Unity contains a NavMesh system: http://docs.unity3d.com/Manual/Navigation.html§ NavMesh concept

› As a preprocess step, figure out where a character could potentially move to/can not move to (can have different “agents” that represent different character types).

› At runtime, use an “agent” that queries the NavMesh to get the path to get from point A to point B.

› You can use the path to do more than just moving a AI character.

Skyrim Clairvoyance Spell (Show Path to Objective)

Page 17: CS248 Lecture 10 - web.stanford.eduweb.stanford.edu/class/cs248/pdf/CS248_Lecture_10.pdf · Assassin’s Creed Unity Cloth. ... › Apply forces to the fractured mesh pieces as …

Live DemoC R E A T I N G

J U S T C A U S E 2 4 8


Recommended