Friday, February 9, 2007

Moving oriented objects in 2D

This is kids stuff for even the amateur games developer,
but for all those aspirants, heres how,

Let x and y be the horizontal and vertical coordinates of your object,
let its orientation be θ.

Assuming you want to displace the oriented object by r units in the direction it is
facing, then,

x = x + r * cos(θ);
y = y + r * sin(θ);

if your using a system in which y axis positive direction faces downwards, then the solution is, (which is the case with many 2D graphics systems). A good example for such a kind of API which uses this kind of 2D graphics system is Adobe Flash, formerly known as Macromedia Flash.

x = x + r * sin(θ);
y = y + r * cos(θ);

Hope this helps, till then, Happy coding!

1 comment:

9ume3jubfo said...

FLOW-3D helps us higher understand processes in cryogenic gasoline dynamics, leading to financial savings in mass and improved launcher performance. FLOW-3D is a complicated tool that gives perception into advanced hydraulic problems that may be difficult to visualize or quantify with different software. Despite the sophistication, the software could be very user how to wash bucket hat friendly, and Flow Science present great documentation and technical support.