• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

Moving Units with X and Y {and PolarProjection()}

Status
Not open for further replies.
Level 17
Joined
Jun 28, 2008
Messages
776
How do you move a unit in a certain direction using SetUnitX and SetUnitY.

I usually do this

JASS:
local unit u
local location p = PolarProjection(point, distance, angle)
local real x = GetLocationX(p)
local real y = GetLocationY(p)

call SetUnitX(u, x)
call SetUnitY(u, y)

There must be an easier way to move a unit in a certain angle, without having to declare another location?

Thanks in advance
 
JASS:
local unit u = GetTriggerUnit()

local real x = GetUnitX(u) + distance * Cos(angle)
local real y = GetUnitY(u) + distance * Sin(angle)
 
call SetUnitX(u, x)
call SetUnitY(u, y)


angle should be in radians not degrees

to convert just use * bj_DEGTORAD and vice versa


E: a bit 2 slow but my solution is 2 lines smaller
 
inline Biatch! :D
JASS:
SetUnitPosition(GetTriggerUnit(),GetUnitX(GetTriggerUnit())+distance*Cos(angle),GetUnitY(GetTriggerUnit())+distance*Sin(angle)
Or if you dont want to interrupt animations use this:
JASS:
SetUnitX(GetTriggerUnit(),GetUnitX(GetTriggerUnit())+distance*Cos(angle))
SetUnitY(GetTriggerUnit(),GetUnitX(GetTriggerUnit())+distance*Sin(angle))
but the difference really is minor..
 
inline Biatch! :D
JASS:
SetUnitPosition(GetTriggerUnit(),GetUnitX(GetTriggerUnit())+distance*Cos(angle),GetUnitY(GetTriggerUnit())+distance*Sin(angle)
Or if you dont want to interrupt animations use this:
JASS:
SetUnitX(GetTriggerUnit(),GetUnitX(GetTriggerUnit())+distance*Cos(angle))
SetUnitY(GetTriggerUnit(),GetUnitX(GetTriggerUnit())+distance*Sin(angle))
but the difference really is minor..

SetUnitX/Y moves the unit while ignoring pathing, so your unit could end up somewhere and get stuck. So if your using SetUnitX/Y makes sure to use some kind of bounds check (so the unit doesn't go outside of map) and pathing check.

SetUnitPosition checks pathing.
 
Status
Not open for further replies.
Back
Top