02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Adding gravity and friction to animations

In this chapter, we will jump right into the Physics2DPlugin that enables us to create 2d physics related animations. In this lecture, we continue exploring the plugin, as we explore the gravity and friction of animations.

Video Transcript

00:00We are back from our break in our last lesson. We created a little gravity pull or more
00:06Actually, we change the angle and the velocity and really that's the next stage that we want to also control the gravity itself
00:13So instead of us going in a direct line where we're going in a specific only what speed are we going also in?
00:19What angle are we going we also want to control the pull of?
00:23Supposedly a
00:25Gravitational effect now to do that is incredibly easy
00:28All we have to do is go back to our code where we were working and add the gravity option
00:34gravity and our gravity we could pull for example a really strong gravity of a hundred would make sure that we're getting pulled down to
00:42Earth really quickly. I'm just gonna make sure that we're going a small distance so we could see it more easily
00:47And if I go ahead here, I save this and I pull on or refresh. We'll see that our pull is very deep
00:52It's taking us all the way to the bottom just to show you the difference if we had a gravity of zero if we didn't have
00:58A gravity the default value of gravity we would then see that we wouldn't have any pull
01:03It would just go in that straight line of our angle until the animation is complete by adding a gravity
01:09We're adding a pull that each
01:12Second we're pulling somewhat something into it
01:14So if we have a gravity pull of 50 what we're basically saying is every second
01:19Pull us more towards Earth in 50 pixels
01:22So if I do that and and it's affecting it you'll see that we're pushing ourselves down towards Earth in
01:2750 pixels per second basically within 150 pixels we were out of our zone of visibility
01:35Now on the other hand we could also use this gravitational pull to be a negative gravity
01:39Which says that we're getting repelled from Earth supposedly and if we do that then our gravitational pull will pull us
01:46Upwards even though our initial angle was 10 degrees
01:50If we wanted to create a more dramatic effect
01:54We would probably want to or a less dramatic effect for that matter
01:58What we could do is change the angle our initial angle to be 20 the angle of 20
02:03So we're pulling towards downwards more and I could reduce the amount of gravitational
02:10Pull or negative pull to make sure that we have most almost like a more full circle
02:15And if I do that, then we'll have a longer stay of our item on our stage as it pulls back up
02:22And literally you could play around and though it with these three
02:25Properties alone the velocity angle and gravity to create everything you really need to
02:31Besides one more thing that we really want to do is add friction and our friction is a value that will be between zero and a hundred
02:38Where if I'll just type it in friction and the idea behind it is just as the name implies
02:42It's saying that will slow us down. Now if we have no friction, we're at zero and the values could be between zero and
02:49One now the value of friction that could be zero if we're setting it zero
02:54We're basically putting the default. There is no friction if we set it to one
02:57We're basically halting it because there is so much friction that it can't move at all
03:02Now if we wanted to create a friction
03:06Usually the values that we would put inside of a friction would be incredibly low value such as 0.01
03:12And that friction will basically slow down our effect overall and it's not a very accurate
03:19mathematical
03:20Effect, but it's a very powerful effect
03:23So if I create this friction and I put here let's say 0.3
03:26You notice the difference in the gap. So if we were came all the way to this e
03:30Just below it this time around our gravitational effect is going to pull us to be way before that there were we
03:38Barely moved into in that zone
03:41Beyond that we could literally the more our
03:44Gravitational we play with our gravity the more we play with our angle the more we play with our velocity
03:49We could create very interesting effects and it's really just a visual game of playing around to figure out what values and what playful
03:58Combinations will create the animation you want to create now
04:02We're not fully done with the do physics 2d plugging because I want to do something really cool with you guys and we're gonna do
04:08That in the next lecture, but before we part I want to talk about beyond our gravity
04:15There are two other controllers when you go into the documentation and I'll leave links in the end of this lesson
04:21Which talk about acceleration and acceleration angle for the most part you could do everything
04:27You need to just using the velocity angle gravity and friction now if you prefer not working with the gravity and
04:35Instead of that working with an acceleration and acceleration angle
04:39You could basically break down the gravity and have more finite control over it
04:44But for us and most animations the gravity is all you need
04:48It's a much more simple way to work
04:50But if you want the more complicated and that gives you a little bit more control over your animations
04:56Then you would use the properties acceleration and acceleration angle, but those two items
05:01We're not going to cover in this video lecture
05:04But you're more than encouraged to ask us questions about it in the comment section below
05:08So see you in the next lecture where we will wrap up our conversation about the do about physics 2d plug-in
05:16Well, we're where what we want to do what I want to do is create a lot of different
05:20Animations going on at the same time and I'm going to show you how to do it
05:24Very quickly and efficiently and the fun way just add a lot of motion really quickly
05:30Which will leave you with a little homework assignment if you'll choose to do it
05:33Which we would love to see your work and your interpretation of the different effects that you create using the plug-in
05:39So see you in the next lecture where we will wrap up this chapter

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!