Collision Size and X/Y

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
So I found that a unit's current X/Y coordinates can be off-centered depending on the unit's collision size. For example, creating a Special Effect at GetUnitX(unit), GetUnitY(unit) might create the special effect slightly offset from the unit's center.

I found that 32 collision size doesn't have this issue but 24 does. I tried some other random numbers like 25 collision and that had the same problem as 24.

Any ideas/solutions? I'd really like to use a collision size of 24 for most of the units in my map but this issue is preventing me from doing so.
 
Level 2
Joined
May 28, 2021
Messages
2
I have same issue. Brother helped me. Big thanks to him for solution!!
Code:
// Get
collision_size = BlzGetUnitCollisionSize(u)
if collision_size < 32.0 and collision_size >= 16.0
    return {GetUnitX(u)-16.0, GetUnitY(u)-16.0}
else
    return {GetUnitX(u), GetUnitY(u)}

// Set
collision_size = BlzGetUnitCollisionSize(u)
if collision_size < 32.0 and collision_size >= 16.0
    SetUnitX(u, x + 16.0)
    SetUnitY(u, y + 16.0)
else
    SetUnitX(u, x)
    SetUnitY(u, y)

// Need to do one for SetUnitPosition too..
 
Status
Not open for further replies.
Top