- Joined
- Dec 3, 2018
- Messages
- 874
I want that when a unit is attacked, it will go in the oposite direction of the attacker, but idk how to do that with triggers. Pls help me!
angle = atand(GetUnitY(targ)-GetUnitY(source), GetUnitX(targ)-GetUnitX(source))
-- Depending on the result, add by pi or 180
angle = angle + 180
-- angle = angle + pi
targLoc = PolarProjection(GetUnitLoc(targ), angle, dist)
Would we not be able to use the attacking unit's facing angle here? I believe it's safe to assume that the attacking unit must face the target unit?Get the angle from the position of the attacked unit to the position of the attacker. Add the resulting angle by 180° (pi if radians), and project the resulting angle from the position of the unit by a certain distance.
In pseudo-code:
Lua:angle = atand(GetUnitY(targ)-GetUnitY(source), GetUnitX(targ)-GetUnitX(source)) -- Depending on the result, add by pi or 180 angle = angle + 180 -- angle = angle + pi targLoc = PolarProjection(GetUnitLoc(targ), angle, dist)