• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Detecting Pathing and Stopping Attack

Status
Not open for further replies.
Level 22
Joined
Jul 25, 2009
Messages
3,091
I have a projectile system, obviously it makes it, where you can't shoot through obstructions, mainly pathing blockers and line of sight blockers, which is what most of my terrain consists, a good 90%. A problem occurs, when the unit wants to fire at a target on the other end of the obstruction, which will, tie the unit up (it'll keep attacking regardless of whether it's hitting anything, I'm pretty sure of this) and it'll waste ammo (each shot is going to use a bullet).

So what I need to do is detect pathing blockers between Point A and B and tell mr. commando not to shoot at anything or specifically that target on the other side of the obstruction. Is it possible?
 
Level 22
Joined
Jul 25, 2009
Messages
3,091
Uh, no that would be pretty much impossible AND I haven't added the projectile system to the particular map yet.

All that happens is, the projectile system, like any other, detects when it reaches a pathing obstruction and then the system kills said projectile (which is just a dummy unit). So if you have a normal auto acquire attack, like for a rifleman in Warcraft 3 Melee, he will keep shooting even if he isn't hitting anything. Problem is, he'll be wasting ammo in my map, so how could I fix this?
 
Level 22
Joined
Jul 25, 2009
Messages
3,091
Obviously I can order the unit to stop attacking lol.......... How do I tell when to order the unit to stop attacking.

It doesn't really matter how I represent ammo? This has nothing to do with that, it has to do with projectiles.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
For static pathing simply iterate through all cells the projectile must path and check if it is pathable.

If your attacks are launched by a custom system then do this as a condition before they are launched. If your attacks are launched automatically by the inbuilt attack system then do this in response to the "unit is attacked" event.

Be aware that this will be quite performance intensive, you may wish to cache results. You should also suggest the unit to attack another target in an order friendly way (if WC3 knows such a thing).
 
Level 22
Joined
Jul 25, 2009
Messages
3,091
For static pathing simply iterate through all cells the projectile must path and check if it is pathable.

If your attacks are launched by a custom system then do this as a condition before they are launched. If your attacks are launched automatically by the inbuilt attack system then do this in response to the "unit is attacked" event.

Be aware that this will be quite performance intensive, you may wish to cache results. You should also suggest the unit to attack another target in an order friendly way (if WC3 knows such a thing).

Let's delve a little deeper into this. All I want to do, is insure, even if they have vision, that units can't shoot through walls and will not automatically target enemies through walls.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
Let's delve a little deeper into this. All I want to do, is insure, even if they have vision, that units can't shoot through walls and will not automatically target enemies through walls.
I already explained...
For static pathing simply iterate through all cells the projectile must path and check if it is pathable.

If your attacks are launched by a custom system then do this as a condition before they are launched. If your attacks are launched automatically by the inbuilt attack system then do this in response to the "unit is attacked" event.

Be aware that this will be quite performance intensive, you may wish to cache results. You should also suggest the unit to attack another target in an order friendly way (if WC3 knows such a thing).
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Simple solution is to make a loop that will advance a point from attacker to the attacked on each iteration and check whether the point is pathable. As soon as you hit an unpathable location, exit the loop and issue a stop order to the attacker.

This is similiar to what Dr Super Good suggested, but it doesn't pick only the cells you need (which you probably don't even have to).
 
Level 15
Joined
Oct 29, 2012
Messages
1,474
Simple solution is to make a loop that will advance a point from attacker to the attacked on each iteration and check whether the point is pathable. As soon as you hit an unpathable location, exit the loop and issue a stop order to the attacker.

This is similiar to what Dr Super Good suggested, but it doesn't pick only the cells you need (which you probably don't even have to).

I guess it will take longer time than the time the unit takes to attack xD poor GUI :/
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
I guess it will take longer time than the time the unit takes to attack xD poor GUI :/

Nah, I did a similar system a while ago. It actually may be helpful to RiotZ.
http://www.hiveworkshop.com/forums/...ranged-attacks-182950/index3.html#post1764452

The difference is that in the linked testmap, the obstacle is a dummy unit called Wall. You can change this in the trigger to check for pathing instead of a wall unit.
Units in the testmap also try to get to a position they can shoot from if they're behind a wall, so you might want to remove that.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Maybe you could trigger the unit's target acquisition and disable the default one, blizzard's default one is persistent in making the unit attack that unit (assuming it is the only target within range) even if you send a stop order via triggers.
 
sorry for the semi-necro but i have an idea that theoretically should work and should also be instantly checked. need knowledge: basic trigonometry. refer to diagram below:
attachment.php

let O (made yellow for ur convenience) = position of triggering/attacking unit
let P = position of attacked unit
let A = a destructable
let r = collision radius of the projectile
let OAB = a hypothetical right-angle triangle, with OA as hypotenuse

let d = distance between O and P
let theta = angle between (facing of attacking unit) and (polar offset of A from O)
sin(theta) = x/d thus dsin(theta) = x

pick every destructable in region with corners O and P
if dsin(theta) > r, then picked destructable isn't obstructing the projectile

basically checking the perpendicular distance from the point of a destructable to the entire projectile path... which makes me now realise that the perpendicular distance formula may also be utilised...
 

Attachments

  • rectcheck.png
    rectcheck.png
    20.6 KB · Views: 315
Level 22
Joined
Jul 25, 2009
Messages
3,091
sorry for the semi-necro but i have an idea that theoretically should work and should also be instantly checked. need knowledge: basic trigonometry. refer to diagram below:
attachment.php

let O (made yellow for ur convenience) = position of triggering/attacking unit
let P = position of attacked unit
let A = a destructable
let r = collision radius of the projectile
let OAB = a hypothetical right-angle triangle, with OA as hypotenuse

let d = distance between O and P
let theta = angle between (facing of attacking unit) and (polar offset of A from O)
sin(theta) = x/d thus dsin(theta) = x

pick every destructable in region with corners O and P
if dsin(theta) > r, then picked destructable isn't obstructing the projectile

basically checking the perpendicular distance from the point of a destructable to the entire projectile path... which makes me now realise that the perpendicular distance formula may also be utilised...

What if I'm not using destructibles?
 
Maybe you could trigger the unit's target acquisition and disable the default one, blizzard's default one is persistent in making the unit attack that unit (assuming it is the only target within range) even if you send a stop order via triggers.

This is what i would go for. Like above mentioned, it is not possible to just order the unit to stop, it will keep aquiring the target many, many times per second. You can take away the units attack altogether by giving it a disabled spellbook containing the orc burrow and cargo hold abilities. To check if the target is hittable, you just use a raycast-like method to simulate the path of the bullet before you shoot it, like people mentioned. The interval between the sample points should be 32 since that is the size of the grid.

At some point though, you will also need to order the unit to move into a position where it CAN hit from. I am not sure how i'd do this, perhaps order it to move towards the target and add it in a certain group which is periodically checked for wether they can hit their target, and when they can, they are ordered to do so.
 
Status
Not open for further replies.
Top