• 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.
  • Vote for the theme of Hive's HD Modeling Contest #7! Click here to vote! - Please only vote if you plan on participating❗️

Unit Displacement bug

Status
Not open for further replies.
Level 14
Joined
Jan 10, 2023
Messages
242
Does anyone have a viable solution to the displacement bug that occurs when two or more units overlap?

The bug works like this, two+ units overlap, everything is fine until one receives an order, upon receiving an order, the ordered unit is displaced to the nearest available location, but this is often outside of the player area or in a 'stuck' location like between trees.

It seems this is a but that would persist in any wc3 environment where units can be placed on top of one another. I can't seem to avoid that, but that would be one solution if there is a way that I haven't found (I am afraid the item-check won't for units with a larger collision size, I may be totally wrong about that)

Any other solutions/ tips?
 
Level 14
Joined
Jan 10, 2023
Messages
242
What causes them to overlap in a first place? Best case scenario, that shouldn't be happening at all

Thank you, and I agree, that's my most-desired solution

That's where I might (try to) incorporate an item-check like Bribe did in his knockback2.5D.

I have a knockback that is piling units on top of one another and I have been unsuccessful at stopping that from happening.

I've tried having the knocked units check if there is already a unit with overlapping collision in the place, but they seem to pass the check no matter the case.

I'm using IsUnitInRange to check. (I'm not at home so I hope you can bare with me here)

I use the XY of the target location and check if there is a unit within 8 range plus the collision size of the knocked unit.
I add those each to a group A, then add group A to group B and destroy group A.
I repeat this with range 16, 32, and 48, each time the on the IsUnitInRange function, I change the filter to filter out the units with lower collision size that have already been checked by the previous IsUnitInRange calls.

The reason I use group A then B is because I think group A is nulled every time I add the in-range-units to group A. Regardless I think this wouldn't cause the problem.

So then I count group B and if group B contains 0 units I use SetUnitXY to move the knocked unit. I know SetUnitXY ignores collision, but checking for obstacles it keeps them in bounds, but when they return to their orders or get a new one, the displacement glitch occurs and then they go out.

Sorry for the lack of code, I'll post it if need be, won't be until the end of my shift today though.
 

Uncle

Warcraft Moderator
Level 71
Joined
Aug 10, 2018
Messages
7,582
It sounds like you want to use the SetUnitPosition() function which will prevent units from ever clipping into one another. You can also use an item to test the "destination point" before moving a unit there. This could be as simple as moving an item to the destination before moving the unit, then testing the distance between the item and destination, and then determining what to do next based on this value. If the distance is too far then we know that our unit will end up somewhere undesirable and we shouldn't run the SetUnitPosition() function.

Note that Items and non-building Units can collide with one another freely. Items will collide with everything else though which makes them useful for detecting most obstacles.
 
Last edited:
Level 14
Joined
Jan 10, 2023
Messages
242
It sounds like you want to use the SetUnitPosition() function which will prevent units from ever clipping into one another. You can also use an item to test the "destination point" before moving a unit there. This could be as simple as moving an item to the destination before moving the unit, then testing the distance between the item and destination, and then determining what to do next based on this value. If the distance is too far then we know that our unit will end up somewhere undesirable and we shouldn't run the SetUnitPosition() function.

Note that Items and non-building Units can collide with one another freely. Items will collide with everything else though which makes them useful for detecting most obstacles.

Hey thanks Uncle,

This seems like the easiest/ best option but I wasn't sure if there was a way to preserve the unit's last order
 
Status
Not open for further replies.
Top