0

I am trying to rotate/pivot an image so that it points towards the center of a circle. However, the math is resulting to be too complicated. For example, I have tried doing things like theta = math.degrees(math.atan((target.x-self.x)/(target.y-self.y))), but this does not take into account the current rotation of my image.

As I am using pyglet, there is a built in variable for the sprite called rotation, which is used to pivot the image anticlockwise.

I have had some ideas like storing the past rotation of the image and doing things like self.rotation = theta + self.past_rotation, but this doesn't take into account things like the fact that the theta = math.degrees(math.atan((target.x-self.x)/(target.y-self.y))) may return negative.

Please I would love help.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
jbg05
  • 51
  • 7
  • Why are negative numbers a problem? Also, I strongly suggest using `math.atan2` rather than `math.atan`. – Stef Feb 12 '22 at 12:18
  • Break the problem into pieces: find the orientation you want the image to have, calculate the change in rotation the image must undergo, apply that rotation. Solve these problems separately, before you try to integrate them. – Beta Feb 12 '22 at 15:16

0 Answers0