HTML and CSS Reference
In-Depth Information
vy += ay;
ship.x += vx;
ship.y += vy;
ship.draw(context);
}());
Test it and fly your ship around. It's pretty amazing just how easily you can make some complex motion
like that.
Important formulas in this chapter
Now you have a few more tools for your toolbox, here they are:
Convert angular velocity to x, y velocity
vx = speed * Math.cos(angle);
vy = speed * Math.sin(angle);
Convert angular acceleration (any force acting on an object) to x,
y acceleration
ax = force * Math.cos(angle);
ay = force * Math.sin(angle);
Add acceleration to velocity
vx += ax;
vy += ay;
Add velocity to position
object.x += vx;
object.y += vy;
Summary
This chapter covered basic velocity and acceleration, the two factors that make up the vast majority of your
programmed animations. You learned about vectors and vector addition. You saw how to accomplish
velocity on a single axis, on two axes, and on an angle by converting it to its x and y components. And you
learned about acceleration—how it relates to velocity and how to apply it to a single axis, two axes, or an
angle.
The biggest thing to take from this chapter is a basic understanding of the application of acceleration and
velocity, as described in the following steps:
 
Search WWH ::




Custom Search