I have myself puzzled... simple math/logic problem
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
I have myself puzzled... simple math/logic problem
I have a Boid class. I was going to implement steering, but... I confused myself. How do you figure out which way to turn if you have a heading(0-360) and a target heading(0-360)? You obviously can't just do a simple comparison of greater than or less than, because 0 < 359, but it'd make more sense to just turn left 1 degree from 0 to get to 359. Hm.
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: I have myself puzzled... simple math/logic problem
(TargetDegrees - SourceDegrees) / 360
Keep whatever is left after the decimal and make it positive.
Test if it is greater or less than 0.5
Keep whatever is left after the decimal and make it positive.
Test if it is greater or less than 0.5
Re: I have myself puzzled... simple math/logic problem
Thanks! I'll try that real quick.
[EDIT] Yay, it seems to work.
[EDIT] Yay, it seems to work.
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: I have myself puzzled... simple math/logic problem
I wrote this and it seems to work:
Sorry, it is in radians.
Code: Select all
function CWorCCW(start,finish)
local half = (finish-start)/(2*math.pi)
local R = half - math.floor(half)
if R<0 then print("CW") end
if R>0 then print("CCW") end
if R==0 then print("Nothing") end
return R*2*math.pi
end
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 51 guests