SetUnitX() seemed to only move my units selection circle, while the unit stayed where it was
SetUnitPosition() did the trick.
Here is my code at the moment:
JASS:
function Trig_Move_Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local location targetPoint = GetSpellTargetLoc()
local real targetAngle = AngleBetweenPoints(GetUnitLoc(caster), targetPoint)
local real targetDistance = DistanceBetweenPoints(GetUnitLoc(caster), targetPoint)
local real targetFacing
...
if (targetAngle < 0) then
set targetAngle = targetAngle + 360
endif
set targetAngle = I2R(R2I((targetAngle / 45) + 0.5)) * 45
set targetFacing = I2R(R2I(targetAngle / 90)) * 90
set targetDistance = Calc_Move_Distance(targetAngle, targetDistance, targetFacing)
// Calc_Move_Distance calculates the distance to the targetted square
...
if ({checks if the target square has a unit in it already, or if the target position is not on the board}) then
call DisplayTimedTextToPlayer(GetOwningPlayer(caster), 0, 0, 5.00, "You cannot move there")
call PauseUnit(caster, true)
call PauseUnit(caster, false)
else
call SetUnitPosition(caster, GetLocationX(targetPoint), GetLocationY(targetPoint))
call SetUnitFacing(caster, targetFacing)
endif
set caster = null
set targetPoint = null
endfunction
...
call TriggerRegisterAnyUnitEventBJ( gg_trg_Move, EVENT_PLAYER_UNIT_SPELL_CAST )
First off, the event. When I tried "Generic unit event - a unit is issued an order targeting a point", the trigger never fired.
Second,
JASS:
call PauseUnit(caster, true); call PauseUnit(caster, false)
seems to throw the trigger into an infinite loop. My guess is I need to throw a wait in there or something.
Third, something with this part:
JASS:
call SetUnitPosition(caster, GetLocationX(targetPoint), GetLocationY(targetPoint))
call SetUnitFacing(caster, targetFacing)
The unit's facing doesn't update until
after it is moved again. While this could be solved by just changing its facing first, what if I don't want to move the piece at all, and just want to rotate it?