How would I go about the math for this?

Cokemonkey11

New Member
Reaction score
18
I want to make system that basically says

if move angle is > facing angle, set move angle = move angle - 1
else set move angle = move angle + 1

There is a problem tho. If move angle is 350 and facing angle is 10, it will turn the wrong way (i think)

So how would I go about setting this up on basically like a number line so that 10 degrees is closer to 350 than 320 is?

Thanks,
 

Flare

Stops copies me!
Reaction score
662
http://www.thehelper.net/forums/showpost.php?p=730887&postcount=6

If I'm understanding what you're saying, you want the unit to turn towards another unit, depending on where the second unit is positioned with respect to the first (i.e. if the target unit is at the left, the first unit will turn anti-clockwise, and turn clockwise when the target unit is at the right)

So, final code would be something like...
JASS:
local unit source = ...
local unit targetUnit = ...
local real x1 = GetUnitX (source)
local real y1 = GetUnitY (source)
local real x2 = x1 + Cos (GetUnitFacing (source) * bj_DEGTORAD) * 100 //Change 100 to any value you like, must be positive though for a correct result
local real y2 = x1 + Sin (GetUnitFacing (source) * bj_DEGTORAD) * 100 //Again, change 100 if you want, must be positive though
if IsUnitLeft (x1, y1, x2, y2, targetUnit) then
  call SetUnitFacing (source, GetUnitFacing (source) + 1)
else
  call SetUnitFacing (source, GetUnitFacing (source) - 1)
endif
//Change the 1 to your facing angle increment
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top