• 🏆 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!
  • ✅ HD Level Design Contest #1 POLL is now OPEN! Check out the stunning visuals of the final entries. 🔗Click here to cast your vote!

SetUnit X,Y to Exact another unit center.

Status
Not open for further replies.
Level 8
Joined
Aug 5, 2014
Messages
189
I have a little problem with trigger which constantly moving one unit using SetUnitX and SetUnitY to the center(exact X,Y coordinates of another unit), and noticed a problem that when unit is moved on this coordinates which i got using GetUnitX and GetUnitY is not exact center, visually it feels like unit a little aside from a center of target unit. Basically im making some sort of a turret, and this method placing in not in exact center of another unit(which his x,y should be, i presume). How to fix that? Does anybody encountered it before?
 
Level 8
Joined
Aug 5, 2014
Messages
189
Hm, thank you! How better to do it? I actually thought about some correction of the coordinates, but i have no expirience in it and i have a question. How to diminish value in WE no matter of its negative or positive value, because unit x or y varies depending on its facing. I mean for example unit X maybe 30 or -30, and i want simply make it 28 or -28 to correct value. Is there some function?
 

Uncle

Warcraft Moderator
Level 62
Joined
Aug 10, 2018
Messages
6,279
I'm not experiencing this issue. Are you sure it's not just an animation issue or maybe the Model itself is offset?

I tested it using this trigger which creates two Footman and moves them on top of one another:
  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
      • Set VariableSet a = (Last created unit)
      • Unit - Create 1 Footman for Player 1 (Red) at (Random point in (Playable map area)) facing Default building facing degrees
      • Set VariableSet b = (Last created unit)
      • -------- --------
      • -------- Move Unit a to the position of Unit b: --------
      • Custom script: call SetUnitX(udg_a, GetUnitX(udg_b))
      • Custom script: call SetUnitY(udg_a, GetUnitY(udg_b))
      • -------- --------
      • -------- Print the x/y coordinates of Unit a and Unit b: --------
      • Custom script: call DisplayTimedTextToForce( GetPlayersAll(), 30, R2S(GetUnitX(udg_a)) + "/" + R2S(GetUnitY(udg_a)) )
      • Custom script: call DisplayTimedTextToForce( GetPlayersAll(), 30, R2S(GetUnitX(udg_b)) + "/" + R2S(GetUnitY(udg_b)) )
This was done on the latest patch. Edit: I changed the Footman's collision and it still worked but I haven't tried two units with different collision sizes.
 

Attachments

  • SetUnitXY.w3m
    16.3 KB · Views: 7
Last edited:
Level 8
Joined
Aug 5, 2014
Messages
189
Thank you for your answer. Im working with old pre reforged version 1.31. Well i've copied your solution and, well indeed it worked like you described, then i replaced footmans with test units. One is siege engine and the second "flag decoration" based on locust. And i've got same situation i had before:
1662160663428.png

As you can see flag a little aside from center. And when i replaced flag with generic unit, the same footman it was placed right at the center. Then i replace a footman model with the same flag for better visual:
1662160888706.png

So the matter in the locust unit. So what might be a problem?
 
Level 8
Joined
Aug 5, 2014
Messages
189
Well, to be correct the problem not exactly in the locust unit, when i tries the same with mortar and footman, i've got this:
1662165558966.png

While using same footmans:
1662165589674.png

So for example, it happening with some units and with others - not. I can place footman in footman, footman in siege enginee, but with locusts and mortar teams, for example happens what you can see on the first screenshot. And they coordinates are indentical.
 
Level 12
Joined
Mar 13, 2020
Messages
421
Well, to be correct the problem not exactly in the locust unit, when i tries the same with mortar and footman, i've got this:
View attachment 406323
While using same footmans:
View attachment 406324
So for example, it happening with some units and with others - not. I can place footman in footman, footman in siege enginee, but with locusts and mortar teams, for example happens what you can see on the first screenshot. And they coordinates are indentical.
Looks like the Mortar has a Rotation in the stand animation or it’s not centered as Model i will Check Later in Retera Model Studio

Edit: didnt saw the picture right your footman is clearly offset he is not in the middle of the mortar...
 
Last edited:
Level 8
Joined
Aug 5, 2014
Messages
189
Looks like the Mortar has a Rotation in the stand animation or it’s not centered as Model i will Check Later in Retera Model Studio

Edit: didnt saw the picture right your footman is clearly offset he is not in the middle of the mortar...
Yes, he is not in the middle, but i place him into mortar, or mortar in him with the same script i use to place footman in footman, moreover script show me that their x and y are identical.
 
Level 2
Joined
May 28, 2021
Messages
2
I have same problem in old patch too! Here is solution for you xD
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..
 
Level 8
Joined
Aug 5, 2014
Messages
189
I have same problem in old patch too! Here is solution for you xD
Well, i've integrated your solution, yes its working, in case with mortar team, but i still have troubles with differen units.
1662308399253.png

(i adopted it in Jass polar projection function, for the test i disabled projection part, simply lefting moving part)
1662304745412.png

How pair moratr and footman works with this function

I thinkg we should solve exact case. I have troubles with Night Elf balista base.
1662304644349.png


While writting this post i've decided to check what the difference between the cases, and the first which came to mind was the collision side, especially after part of the code in your solution checking that collision. After that i've noticed that higer number of this check is 32, which is exact collision sive of the mortar team, i quickly changed collision sive of the ballista to the collision sive of 32. Result i had.
1662305472227.png

Its hard to see, but the footman right in the center of the ballista, you can notice a little part of the shield, poping under center blade of a glaive to the left. Pwnica was right. Coliision in this case matters.

And it solved the problem i had with tha main unit for which i did this trigger.

So developing this idea, if i want to use old collision 48.00 i need change this function, replacing 32 with 48 and 16 with 24?

Well, i actually tried it(function aimed for unit with 48.00 collision size, which i discribed above), and result wasnt so smooth. But that atleast something.
How better adjust this function for such cases?

And after that, i've noticed that after setting collision size on 32, other attached units, which i attach without using function with implemented collision check, positioned correctly, i've decided to test ballista unit with locust based unit with simple SetUnitX and Y without collision checks, and found out that for that case, i dont need this function at all, because changing collision on 32 fixed that alone. But still it we can say the system is working on case when in place of locust turret was fotman and in case with mortar and footman. So the main question, how to handle collision size larger than 32?
 
Level 8
Joined
Aug 5, 2014
Messages
189
This baffles me, and I’m inclined to believe it’s not what’s actually at play here. I figure someone else would have noticed this in 20 years of mapping.
Well maybe its the case of instability of 1.31. its really buggy, and this is not the single problem i've encountered working with it. Maybe i see something wrong. But when i used the function which yenualed provided to me, AND set collision size of problematic unit to 32(size of two little dwarfs) everything start working as i want it to. And in some cases, as in case with locust unit, its working correctly even with standart SetUnitX,Y. Thats all what can i say right now in short. Really, even i feel that my eyes deciving me here right now, so i understand your feelings.
 
Level 14
Joined
Jan 16, 2009
Messages
715
@Pyrogasm This issue has been noticed before by @Retera back in 2015 and others throughout the years.
It is easily testable by creating a unit of collision size 16 or 48 and then creating a special effect using
a torch model on its position.
Code:
create_unit(players[0], W3_UNIT_IDS.ACOLYTE, point)
create_special_effect(W3_DOODAD_MODELS.TORCH_HUMAN, point)

@darkravenbest The problem still exists on latest patch and seems the code that was posted before only fix it for one collision range and not for the other. This is why you had issues with the ballista.

A unit can have 4 different sizes on the pathing grid (see this post about it).

Size 2 (2x2) and 4 (4x4) are the bugged ones for non building units.
Basically the units with pathing size 2 and 4 will have their coordinates off by 16 (half a tile's cell).

The following is some pseudo-code to get that offset.
Code:
function get_xy_offset(unit u) returns real
    if is_of_type(u, UNIT_TYPE_STRUCTURE)
        return 0.

    let grid_size = to_int(get_collision_size(u)) / 16 // Int division.
    if grid_size == 1 or grid_size >= 3
        return 16.

    return 0.
Add it to x and y when setting a position and remove it when getting a position.
 
Status
Not open for further replies.
Top