Public Group

#### Archived

This topic is now archived and is closed to further replies.

# difference between angles (-180 to +180)

This topic is 5714 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi. I''m just a hobby game programmer but have recently run into a problem a few weeks ago that I can''t seem to work out. I have a delayed camera that rotates around my character, using the difference between the angles to smoothly rotate the camera around it. The problem is when I get to 180 and cross over into -180 the simple subtraction formula doesn''t work. Plus, if I have for example, -175 to +175 I don''t get the correct difference, it should be 10. Can anyone point me in the right direction on how I should be approaching this?

##### Share on other sites
Why use -180 to 180? Why not just go from 0 to 360? If the angle ends up above 360, just subtract 360. If it ends up below zero, just add 360. Seems simple enough.

Of course, the same could be done with your method, but 0 to 360 seems simpler to me.

[edited by - micepick on April 19, 2003 11:10:09 AM]

##### Share on other sites
the +180->-180 angles are only used for first person cameras for other cams use 0->360 as stated above

##### Share on other sites
Thank you guys so much ! You opened my eyes to the simple solution. After trying so many techniques I ended up only needing two lines right after I determin the difference:

If diffY > 180 Then diffY = diffY - 360
If diffY < -180 Then diffY = diffY + 360

1. 1
2. 2
3. 3
Rutin
19
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633659
• Total Posts
3013208
×