• 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.

How to instantly move the unit to enemy's back?

Status
Not open for further replies.
Level 22
Joined
Sep 24, 2005
Messages
4,821
First get the facing angle of the target, then add 180 degrees to it. Polar project the caster x distance with target's angle + 180. After that set your unit's facing the same as the target's.
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
  • Sample Trigger
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Whatever Ability
    • Actions
      • Unit - Move (Casting unit) instantly to (Position of (Targeted unit))
That won't do. Not only does it leak location, it will also move the caster to random position around the target. Geshishouhu wants fixed location - behind the target.
 
Level 10
Joined
Apr 18, 2009
Messages
601
The key lies in understanding the Point With Polar Offset function.

Here's how you do it:
  • Ability
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Your Ability
    • Actions
      • Unit - Move (Triggering unit) instantly to ((Position of (Target unit of ability being cast)) offset by 100.00 towards ((Facing of (Target unit of ability being cast)) - 180.00) degrees)
Your Ability should of course be an ability with a unit target (like Storm Bolt) for this to work properly.

I've attatched a map using Storm Bolt as example ability to trigger off of. Study the trigger, learn about the function and implement it with your own ability.
 

Attachments

  • Move Hero Behind Target.w3x
    16.7 KB · Views: 51
Level 11
Joined
Oct 11, 2012
Messages
711
That won't do. Not only does it leak location, it will also move the caster to random position around the target. Geshishouhu wants fixed location - behind the target.

Yup, you r right.

The key lies in understanding the Point With Polar Offset function.

Here's how you do it:
  • Ability
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Your Ability
    • Actions
      • Unit - Move (Triggering unit) instantly to ((Position of (Target unit of ability being cast)) offset by 100.00 towards ((Facing of (Target unit of ability being cast)) - 180.00) degrees)

Your Ability should of course be an ability with a unit target (like Storm Bolt) for this to work properly.

I've attatched a map using Storm Bolt as example ability to trigger off of. Study the trigger, learn about the function and implement it with your own ability.

Thanks for the idea and making the trigger.
Edit: But after the move, the hero is not facing the target's back, he needs to turn around a bit. How to fix that?

@chobibo
Thanks for the idea.
 
Last edited:
Level 11
Joined
Oct 11, 2012
Messages
711
That trigger leaks. You have to save Position of Targeted unit into point variable first and then save the Offset point into another point variable.

For efficiency sake, it may be better to also save targeted unit into variable xD

Alright, thanks. Do you know how to set the hero's facing after the move? I want it to face the target's back. I set the facing angle the same as the target but it didn't work out.

Edit: if the hero and the target were facing each other before the move, then the hero needs to turn around after moving to the target's back. What I want is that the hero faces the target's back after the move, no need to turn around. :)

Edit: it works, thanks guys!

Edit: should I use the following code instead of using PolarProjectionBJ?
JASS:
local real x1 
local real y1
local real x2
local real y2

local real dx=x2-x1
local real dy=y2-y1

local real angle=Atan2(dy,dx) 
local real distance=SquareRoot(dx*dx+dy*dy) 



set x2=x1+distance*Cos(angle)
set y2=y1+distance*Sin(angle)

I hope DIMF can see this, LOL
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Why are you setting the distance like that? Shouldn't it be constant. (100 10~50 units for melee attack)
The projection seems fine.
 
Alright, thanks. Do you know how to set the hero's facing after the move? I want it to face the target's back. I set the facing angle the same as the target but it didn't work out.

Edit: if the hero and the target were facing each other before the move, then the hero needs to turn around after moving to the target's back. What I want is that the hero faces the target's back after the move, no need to turn around. :)

Edit: it works, thanks guys!

Edit: should I use the following code instead of using PolarProjectionBJ?
JASS:
local real x1 
local real y1
local real x2
local real y2

local real dx=x2-x1
local real dy=y2-y1

local real angle=Atan2(dy,dx) 
local real distance=SquareRoot(dx*dx+dy*dy) 



set x2=x1+distance*Cos(angle)
set y2=y1+distance*Sin(angle)

I hope DIMF can see this, LOL

It is always easier to make a function you use to return the distance. You can use that function and only have to make it once.
Also use one for the angles. ( i believe it has it in spell below.)
Look at my implosion bomb spell. ( i believe it has it in that one.)

When getting angle like said use the facing angle + or - 180. ( doesn't matter)
To make the unit face the angle of the unit that you base the facing angle off of. Get the units facing angle and face it that way.
Remember to set facing when creating unit otherwise you have about .5 second facing angle delay. ( worst case)
 
Level 11
Joined
Oct 11, 2012
Messages
711
Why are you setting the distance like that? Shouldn't it be constant. (100 10~50 units for melee attack)
The projection seems fine.

The distance setting is just a general one, not relevant to this spell. And you r right, I think it should be a constant is this case.

It is always easier to make a function you use to return the distance. You can use that function and only have to make it once.
Also use one for the angles. ( i believe it has it in spell below.)
Look at my implosion bomb spell. ( i believe it has it in that one.)

When getting angle like said use the facing angle + or - 180. ( doesn't matter)
To make the unit face the angle of the unit that you base the facing angle off of. Get the units facing angle and face it that way.
Remember to set facing when creating unit otherwise you have about .5 second facing angle delay. ( worst case)

Thanks! I'm glad you see this, LOL. I will check your spell.
What do you mean by "setting facing when creating unit"? Shouldn't I set unit position or x,y first, then call SetUnitFacing?
 
Status
Not open for further replies.
Top