Tip:
Highlight text to annotate it
X
[MUSIC PLAYING]
TODD KERPELMAN: Hello game developers,
and welcome to yet another exciting episode of "Game On!"
I am Todd Kerpelman.
I'm a developer advocate here on the Google Play Games Team.
And here with me today is Wolff Dobson,
developer programs engineer, also on the Play Games Team.
And he is here to talk about one of my most favorite things
in the whole wide world and that is physics engines.
So Wolff, why don't you take it away?
WOLFF DOBSON: Alright.
So today we're going to talk about Liquid Fun.
This is our brand new open source physics engine that
we've just released cross platform in C++.
TODD KERPELMAN: Very exciting.
WOLFF DOBSON: Mmhmm.
So first thing we should talk about is, where do you get it?
And our producers here have added a link
that you can click on that'll take you
straight to our GitHub page.
And in this little chat here we're going to do an overview.
We're going to do some demos and we'll even
talk about a little code.
So, first, let's talk about physics engines.
TODD KERPELMAN: What's a physics engine Wolff?
WOLFF DOBSON: It's your favorite thing in the world.
TODD KERPELMAN: Oh, that's right.
WOLFF DOBSON: So, a physics engine
is the mathematical simulation that
helps you create procedural animations filled
with physical bodies.
So in a game, you're simulating per frame.
And the system divides times into little slices and updates
on all the objects each frame based
on their positions and velocities.
So there are conflicts, like collisions,
then the system resolves those safely.
The most basic physics simulation you can think of
is actually "Pong."
A single body, it's moving around,
bouncing off against two paddles.
TODD KERPELMAN: I guess that's true.
WOLFF DOBSON: This is obviously a little bit more complicated.
Liquid Fun, that we're providing,
is just a numerical simulation.
We have a little simple visualization, but in your game
you're going to want to add art, and sound, and story, and all
the rest of that stuff.
This is just the mathematical part.
TODD KERPELMAN: So like in a model view controller
kind of analogy, this would be the model.
This is telling you where everything is in my game,
but it would be up to my game to actually take that information
and turn that into something on-screen
that I would present to my player.
WOLFF DOBSON: Exactly.
TODD KERPELMAN: Alright.
WOLFF DOBSON: So, this is a superset of Box2D.
Box2D, I'm sure you've heard of.
TODD KERPELMAN: Box2D, yes.
It's a very popular 2D physics engine developed by Erin Catto,
I believe, and it's used in just about any game
out there that uses physics.
I know "Angry Birds" uses it.
WOLFF DOBSON: Anything with 2D physics has Box2D in it.
TODD KERPELMAN: There's a pretty good chance
that it's using Box2D.
WOLFF DOBSON: If your game uses Box2D,
you should be able to drop this engine in
and it will just work.
So just as a view, this is the typical--
this is our typical [? system ?] demo here
that shows just rigid bodies interacting with each other.
TODD KERPELMAN: This is demonstrating
a lot of interesting things, right.
It's sort of demonstrating first, gravity,
and also momentum, and I guess you'd
see angular momentum if that--
WOLFF DOBSON: Joints too on the thing and motors
turning the thing.
But this is all very standard Box2D stuff.
The sort of special sauce we're adding with Liquid Fun
is, obviously, Particles.
TODD KERPELMAN: Oooh.
WOLFF DOBSON: Yes.
So let's look at some particle demos.
This is a whole bunch of particles
and a giant rigid body slamming into all those particles.
TODD KERPELMAN: Wow.
WOLFF DOBSON: Yeah, that's a lot of particles.
That's thousands and thousands of particles running around
inside there.
And this is an active simulation.
So if I grab hold of this, I can kind of swim through this
and push these guys out of the way.
I can touch groups of particles and throw them around.
It's pretty cool.
TODD KERPELMAN: Yeah.
Because normally when I think of particles,
I think of them used for, sort of,
visual only effects, like fire and smoke.
But I guess what you're saying is particles could also
be used for generating things that look like water.
WOLFF DOBSON: Yeah, exactly.
And these particles are actually--
and these particles can interact with the entire rest
of your physical system.
This is your typical wave machine.
You can actually see wave physics
going back and forth as it swims around.
TODD KERPELMAN: Gotcha.
And so, basically this engine is simulating
each of these thousands of particles individually,
and sort of, by grouping all these behaviors together,
you get something that suddenly creates waves.
WOLFF DOBSON: Yeah, it looks like water.
It's pretty neat.
TODD KERPELMAN: Yeah, that's cool.
WOLFF DOBSON: So, as I mentioned before, the engine is
cross platform.
It's written in C++.
And we provided builds out of the box for Android NDK,
obviously.
We also have Linux, OSX, Windows,
and people can feel free to contribute
to whatever other platforms they want to add.
TODD KERPELMAN: Gotcha.
So there's a pretty good chance I could add this
to any mobile game I wanted.
WOLFF DOBSON: Mmhmm.
TODD KERPELMAN: Alright.
WOLFF DOBSON: So, this is kind of way out of scope,
but we'll talk a little bit about how physics engines work.
So in a physics engine, you basically create a world.
You add some rigid bodies to it.
So here, a circle and a triangle.
You might add some joints to connect them.
And then you step the simulation forward.
In this case, since there's nothing supporting those guys,
there's just going to fall.
But again, the secret sauce with Liquid Fun
is that we're adding very large numbers of particles that
can interact with these rigid bodies.
TODD KERPELMAN: OK.
So what makes a particle different than a rigid body?
WOLFF DOBSON: So particles are the smallest unit of matter
that can interact with things.
They act like rigid bodies, but they don't have rotation.
So we consider them uniform circles.
And they are, sort of, packed intelligently in the system
so that they can be rendered and simulated very quickly.
TODD KERPELMAN: OK.
WOLFF DOBSON: Rigid bodies, basically,
are going to be slow and expensive,
and particles are small and cheap.
TODD KERPELMAN: OK.
So by basically placing a few limitations on these things,
the engine is then able to render
hundreds or thousands of them at once.
WOLFF DOBSON: Thousands, definitely.
TODD KERPELMAN: OK.
WOLFF DOBSON: So particles come with
basic physical characteristics like color, size, position,
velocity.
Color is for your reference when you're rendering them.
It doesn't actually have any effect
on the numerical simulation.
TODD KERPELMAN: Gotcha.
I can ping the model and say, hey, what's this?
WOLFF DOBSON: What color is this?
And then also, strength.
So if you have particles that are sort of stuck together,
like viscous particles, you can say
how strong you want that viscosity to be.
TODD KERPELMAN: OK.
WOLFF DOBSON: And as noted, there's
no rotation for particles.
So if you rendered them as little top hats,
the top hats would always be facing up
even though thousands of them are
smacking against each other.
TODD KERPELMAN: Gotcha.
So as a general rule, you probably
don't want to render them as something
that-- where you would notice it doesn't rotate.
WOLFF DOBSON: Yeah, exactly.
TODD KERPELMAN: In fact, most likely
I might apply some sort of filter
to not show the individual particles, but kind of group
them together so I might see a big wave or something.
WOLFF DOBSON: No, actually, in these simulations,
we're just sort of rendering a gaussian spot.
TODD KERPELMAN: OK.
WOLFF DOBSON: And as lots of them
are-- as they sort of-- the spot is a little bit bigger
than the body, and as they overlap each other,
you get the sort of the areas that look kind of solid.
TODD KERPELMAN: OK.
WOLFF DOBSON: So here's the code for creating a particle.
If you've used Box2D before, this
should seem really familiar.
You create a particle Def.
You can set some flags on it.
And you can also set its position and its velocity,
but not its rotation.
And then you tell the world I'd like
to create a particle using this definition.
TODD KERPELMAN: What does elasticParticle there mean?
WOLFF DOBSON: So elastic particles
are springy particles.
They're particles that are connected together
like a jelly.
We'll see one in just a minute.
TODD KERPELMAN: Alright.
WOLFF DOBSON: We'll see a lot of elastic particles
in just a minute.
A particle group is created by instancing sets of particles
together in a shape.
They're ways for you to create and destroy lots of particles
at the same time.
So you can set all the regular properties
like velocity and position.
But you can also add the rotational angle
if you have one of these jellies.
You can also set-- sorry, you can rotate the shape
and then you can set the rotational velocity
as well if you have one of these jellies.
TODD KERPELMAN: So particles don't have rotation,
but a particle group does have a rotation.
WOLFF DOBSON: If it's an elastic one, yeah.
TODD KERPELMAN: OK.
I think.
I think you're going to need to show me a demo.
WOLFF DOBSON: I think we're going to show a demo.
TODD KERPELMAN: Alright.
WOLFF DOBSON: So creating particle groups is,
again, should feel pretty familiar to Box2D people.
You create a shape, You create a particle group definition
object, and then you instance the group with that.
So--
TODD KERPELMAN: What does the shape here mean?
WOLFF DOBSON: A shape is a Box2D primitive.
So it's going to be a polygon.
So you can make a circle.
You can make a giant square.
You can make it L-shaped.
You can do whatever you want.
TODD KERPELMAN: And is the idea these particles have
to fit into that shape?
WOLFF DOBSON: It will create particles
with the density in the shape that you specify.
TODD KERPELMAN: Hmmm-- OK.
I'm a little confused.
Maybe you can go through this code
and let me know what you mean.
WOLFF DOBSON: Right.
So you can see here we have the particle group
definition and a shape.
The shape is just a box.
And then on the particle group definition we're saying,
look at this shape.
We're setting some flags on it-- its initial angle,
its initial angular velocity-- and that's
the angle of the entire shape that we're setting.
And then we're instancing five groups of these all at once.
TODD KERPELMAN: So you're creating-- I see--
you're creating five groups of--
WOLFF DOBSON: Of square shaped particles.
TODD KERPELMAN: But then within these, you
do need to, then, create the particles
that are attached to these shapes?
WOLFF DOBSON: No.
When you say create particle group, you just [whoomp],
you instance all of these particles at the same time.
TODD KERPELMAN: Oh, OK.
And so that's where the shape definition comes in,
is it's creating these groups that-- these groups
of particles that essentially fill this shape.
WOLFF DOBSON: Yeah.
TODD KERPELMAN: Gotcha.
And the density of particles within that shape,
is that something that I would specify?
WOLFF DOBSON: Yeah, you can set the particle size.
TODD KERPELMAN: OK.
So I don't need to have four nested--
{four} {loops} that create all these thousands of particles.
WOLFF DOBSON: No, no, no, no.
You just make a shape and it will fill it with particles.
TODD KERPELMAN: Well that makes a whole lot more sense.
Alright.
WOLFF DOBSON: So if you want to destroy particles as a group,
it's pretty easy.
This code example here walks the entire list
of groups in the world and just destroys all of them.
This would be like a simulation shutdown step.
The particles in the groups can interact with each other,
but then you can kill the groups en masse.
TODD KERPELMAN: So let's say I have two groups here,
and I mix them all together, and they form this giant mess,
I could then say kill group A and, like, half my water will
suddenly disappear.
WOLFF DOBSON: Exactly.
TODD KERPELMAN: Huh.
So I guess you've got to be careful about using
that to make sure that that's actually the side effect
that you want.
WOLFF DOBSON: Exactly.
TODD KERPELMAN: OK.
WOLFF DOBSON: Once you start pouring liquids together,
they become intermeshed.
TODD KERPELMAN: Yes.
WOLFF DOBSON: Particles have a lot of different behaviors.
By default, they operate as a simple liquid,
but you can add these new particles, like elasticity,
with flags.
So let's share some demos here.
TODD KERPELMAN: OK.
WOLFF DOBSON: So first I'm going to show you
a set of particles that are elastic.
So here you can see they're kind of acting like jelly.
And if I grab any small collection of particles
and move them, the whole body moves at the same time.
TODD KERPELMAN: Gotcha.
And I can see they're trying to keep, sort of,
their original shape.
WOLFF DOBSON: But they can still be
deformed if I drop objects on them.
They're going to, sort of, deform to accept that.
TODD KERPELMAN: And so these were
created by particle groups.
WOLFF DOBSON: Mmhmm, yeah.
TODD KERPELMAN: One has the shape that's a circle,
the other has a shape that's a rectangle.
You've given them elasticity--
WOLFF DOBSON: Right.
TODD KERPELMAN: --Which means that they are springy and they
cannot be broken apart.
WOLFF DOBSON: Right.
TODD KERPELMAN: OK.
So that would be useful for like,
if I wanted to create bouncy balls or just fun
looking jelly types of things.
WOLFF DOBSON: Like this.
TODD KERPELMAN: Yes.
WOLFF DOBSON: Because it's such a cool jelly.
TODD KERPELMAN: And somehow it's important for my game
to make sure that this is still one solid object, it doesn't
get broken apart.
WOLFF DOBSON: Right.
TODD KERPELMAN: OK.
WOLFF DOBSON: So here's an example
of particles that can color mix.
So this is a regular fluid, but as the particles brush
against each other, it averages their color as they rub.
So you can see the red and green turned
into this yellow on the left.
And If I kind of mix these-- woops,
I kind of spilled-- if I mix these,
I can kind of bring the green into the blue
and get kind of a uniform light blue.
TODD KERPELMAN: Gotcha.
And so these colors basically mix just
based on when they touch?
WOLFF DOBSON: Yeah.
TODD KERPELMAN: So I could-- let's say,
as a developer-- I could use this
if I wanted to measure some hot water and some cold water
or something.
I would just sort of ping the color
as a way to represent how hot or cold these things are.
WOLFF DOBSON: Sure.
TODD KERPELMAN: OK.
And so, I noticed these break apart very easily.
So these are not elastic particles.
WOLFF DOBSON: No, no.
These are regular fluids.
TODD KERPELMAN: OK.
WOLFF DOBSON: And lastly, here are some viscous fluids flowing
through a maze, and then we have a couple little pumps that
are moving it back and forth.
And you can see I'm getting this sort of blob
down here in the lower left.
TODD KERPELMAN: Mmhmm.
WOLFF DOBSON: And, also, if you look up at the right,
you can see I'm applying a constant force to this pump,
and it can't compress this viscous fluid enough,
so it bounces off of it.
TODD KERPELMAN: Sort of like real water, I guess.
WOLFF DOBSON: Exactly.
TODD KERPELMAN: Right.
WOLFF DOBSON: And then down here at bottom-- oh,
there it fell by itself-- I can use this to sort of pump water
uphill.
And knock this other rigid body into the drain.
TODD KERPELMAN: And so, by saying
these are viscous, what you're basically saying is, like,
these have some amount of surface tension?
WOLFF DOBSON: Mmhmm, yeah.
[INTERPOSING VOICES]
WOLFF DOBSON: [INAUDIBLE] want to stick together.
TODD KERPELMAN: This gives me more realistic
looking water than if they were not.
Like it would probably look like sand
if you did not have this viscosity turned on?
WOLFF DOBSON: Yeah.
It would look more-- it wouldn't go here as much.
You would end up with as many of these sort of big blobs.
TODD KERPELMAN: Gotcha.
And the more and more viscous, the more and more you
go from water to, like, toothpaste or something.
WOLFF DOBSON: Yeah, exactly.
TODD KERPELMAN: Alright.
Maybe maple syrup.
I'm trying to think of fluids with high viscosity--
WOLFF DOBSON: Slime.
TODD KERPELMAN: Yes.
WOLFF DOBSON: Something like that.
TODD KERPELMAN: OK.
WOLFF DOBSON: And we have more particle behaviors
besides even these, like powder, and tensile, and wall,
and things like that.
TODD KERPELMAN: What do those mean?
What does powder mean?
WOLFF DOBSON: So powder would be something like smoke.
It would be things-- it doesn't stick to walls very well
and it doesn't want to stick to itself very much at all.
So that's powder.
You can read more about all of these in the user manual
that we have.
And speaking of our user manual, come on by to our GitHub page.
Join us.
We have a discussion group.
And we have a programmers manual,
and we have an API reference, and have all the source
TODD KERPELMAN: Cool.
So what's the license on this?
You said it's open source?
WOLFF DOBSON: It's open source.
You can pull it into your game right now, and publish it,
and that would be great.
TODD KERPELMAN: Awesome.
Well that sounds like a very useful thing.
WOLFF DOBSON: Mmhmm.
TODD KERPELMAN: Why are we giving this
to the world, Wolff?
WOLFF DOBSON: Because we want to make games better.
TODD KERPELMAN: Oh.
Well, that's a good idea.
WOLFF DOBSON: We want to make people's games awesome.
TODD KERPELMAN: Alright, well this seems like a good start.
As someone who is a big fan of physics games,
I encourage you all to take a look at this
and start adding crazy-looking jelly things to your game.
There's probably a whole world of water
and jelly games that we just--
WOLFF DOBSON: There's a genre of jelly games.
TODD KERPELMAN: --just waiting to be discovered.
And so maybe that will be you.
Yeah, seriously check it out.
I think physics engine I always just find really interesting,
because it's like a very complicated system where you
can have a lot of rich behavior and create a lot of really
interesting, rich puzzles, but at the same time,
a three-year-old intuitively understands
how everything in the world is going to react.
[INTERPOSING VOICES]
TODD KERPELMAN: So I think it makes for a really good game
design.
That's, I think, why there's so many good physics-based game
designs out there.
WOLFF DOBSON: It's really a sandbox for emergent gameplay.
Unexpected things happen when you put physics together,
and that makes it surprising and fun.
TODD KERPELMAN: Or you could really just make this wave
machine, and I'd watch that for several hours.
WOLFF DOBSON: Yeah, you get hooked just
looking at these things.
TODD KERPELMAN: So you said OSX.
Can I make a screensaver using this stuff?
WOLFF DOBSON: If you want to.
TODD KERPELMAN: Awesome.
Alright, well I know what I'm doing over the winter break.
Alright, well thank you everyone for joining us.
Take a look at what we've got at our GitHub page.
I think it'll be pretty interesting.
And we will see you all in a week or two.
Bye.
WOLFF DOBSON: Bye.