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

[JASS] Detect Units Behind

Status
Not open for further replies.
Level 9
Joined
May 28, 2007
Messages
365
I have to say I'm a little confused on what you are asking, and clarification would help.

You can use PolarProjectionBJ in a way to enum things in front and behind

Example:
local unit u = YourUnit
PolarProjectionBJ(GetUnitLoc(u), 50, GetUnitFacing(u)) // A point in front of unit
PolarProjectionBJ(GetUnitLoc(u), -50, GetUnitFacing(u)) // A point behind the unit

Then you can use CreateGroup and enum units in the new point, to detect unit collision and do the same to detect destructables such as trees.

Of course this isn't the most efficient way to do it, and I never really reccomened using PolarProjectionBJ, but rather create your own functions that do the same thing, if you can. Otherwise, this solution should get the job done and giv eyou some insight anywya. I'll leave the optimization to you.

Good luck!
 
Level 8
Joined
Jun 18, 2007
Messages
214
I have to say I'm a little confused on what you are asking, and clarification would help.

You can use PolarProjectionBJ in a way to enum things in front and behind

Example:
local unit u = YourUnit
PolarProjectionBJ(GetUnitLoc(u), 50, GetUnitFacing(u)) // A point in front of unit
PolarProjectionBJ(GetUnitLoc(u), -50, GetUnitFacing(u)) // A point behind the unit

Then you can use CreateGroup and enum units in the new point, to detect unit collision and do the same to detect destructables such as trees.

Of course this isn't the most efficient way to do it, and I never really reccomened using PolarProjectionBJ, but rather create your own functions that do the same thing, if you can. Otherwise, this solution should get the job done and giv eyou some insight anywya. I'll leave the optimization to you.

Good luck!

Alright, thank you, I never use locations so the optimization is not a problem xD. I had that in mind as well, but that gives me a new coordinates behind a let's say hero (or in front), but I still have to pick units in circle, I wasn't really sure how accurate that is, so i wanted to see if someone has found a better solution :p. Anyways ty for trying to help.

Let's say I want to make this spell:

The caster throws a spear at a targeted enemy unit. When unit gets hit by a spear it will be pushed back. The target will stop when either the force of the throw stops, of if he hits the unit behind him, in which case both units would be stopped and stabbed for a short duration.


Now nothing here is a really a problem, except detecting units behind the targeted one.
 
Level 17
Joined
Sep 8, 2007
Messages
994
Alright, thank you, I never use locations so the optimization is not a problem xD. I had that in mind as well, but that gives me a new coordinates behind a let's say hero (or in front), but I still have to pick units in circle, I wasn't really sure how accurate that is, so i wanted to see if someone has found a better solution :p. Anyways ty for trying to help.

Let's say I want to make this spell:

The caster throws a spear at a targeted enemy unit. When unit gets hit by a spear it will be pushed back. The target will stop when either the force of the throw stops, of if he hits the unit behind him, in which case both units would be stopped and stabbed for a short duration.


Now nothing here is a really a problem, except detecting units behind the targeted one.

Srsly, don't! PolarProjection is like trying to kill fire with petrol ...
I'll edit this post later to give a better example...

Edit: So, basically, what you're looking after is a detection system. There may be some nice detections in the spell section.
Though, unit detection is a lil different than pathability/doodad detection ... well, though it is easy ^^
If you really can't find what you need here, you can contact me later ...
 
Level 17
Joined
Mar 17, 2009
Messages
1,350
I don't think what you want is whether something is behind or in front of a unit, but if the unit collided with something.

Simple, you need a GroupEnumUnitsInRange(g, x, y, COLLISIONRANGE, null)
(although here the null leaks a filterfunc, use a true boolexpr global instead),
and then ForGroup(g, function STOPACTION) (a function that stops the motion)

+ you need EnumDestructablesInCircleBJ(COLLISIONRANGE, loc, function STOPACTION)
(if you know how to do the circle shape using EnumDestructablesInRect, then use that instead)

Now to detect the unit behind the moving unit, well take a look at Sweltering Blaze in the Metaversal Spell Pack in my signature, there I pick the units looking at the caster, taking -60 to +60 angle from facing. You do almost same thing, but -120 to -60 angle (or something like that) from the moving unit's facing. And then you could use GetClosestUnit system from the Jass section just to avoid that it hits more then one unit.
Although i think all this is useless, since it's actually impossible to hit a unit in front of the moving unit in case the collision radius is low (30 for example), and the simple enumming I mentioned in the beginning should do the job...
 
Status
Not open for further replies.
Top