[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] [OT]move



To move an object those two versions seem to work:

x += speed * sin(angle)
y += speed * cos(angle)

x += speed * cos(angle)
y -= speed * sin(angle)

which is the best?

It depends on the coordinate system you set up. Computer graphics
tend to use a system where (0,0) is the upper left corner of the screen
and positive x is to the right and positive y is down. I tend to measure
angles with angle 0 being along the x axis and positive angles being
counter-clockwise.

With that setup, I would say that to move an object:

x += speed * cos(angle)
y -= speed * sin(angle)

would be correct.

As long as you are consistent, and document your setup, I do not
think it makes much difference.

When I am trying to get these algorithms correct, I usually have a
bunch of little diagrams in front of me with my coordinate axes and
some arrows drawn in. It helps to keep all the plusses and minuses
straight.

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963