Author Topic: [Bug] Melee attack hits terrain instead of unit  (Read 1175 times)

Online Delian

  • Colonel
  • ****
  • Posts: 492
    • View Profile
[Bug] Melee attack hits terrain instead of unit
« on: August 15, 2024, 11:29:29 am »
1. Load the .sav
2. Fist the enemy unit
3. Keep fisting

Current behavior: Enemy doesn't get hit, and the hit log registers misses (terrain hits normally don't register)
Expected behavior: Enemy should get hit, and the hit log should registers hits

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9077
    • View Profile
Re: [Bug] Melee attack hits terrain instead of unit
« Reply #1 on: August 25, 2024, 01:24:12 pm »
Normal vanilla behavior.


The center of the enemy -- voxel (8,8,11) -- is obstructed by terrain, more specifically by the northwall part of the tile.

Melee attack hits terrain.
(Note: this has nothing to do with OXCE terrain melee feature, this happens also in OXC)


In PirateZ:
1. you keep punching northwall and never break it
2. goto 1


In TFTD:
1. vibro blade hits northwall a couple of times, until RNG rolls high enough to break it
2. northwall MCD is replaced (by dieMCD), which has different loftemps... and doesn't obstruct the target voxel (8,8,11) anymore
3. vibro blade hits gillman a couple times (miss and damage RNG can take a couple attempts)
4. gillman dies


See attached debugging notes, maybe you can make something out of it.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9077
    • View Profile
Re: [Bug] Melee attack hits terrain instead of unit
« Reply #2 on: August 25, 2024, 01:25:01 pm »
TLDR: fix your loftemps

Online Delian

  • Colonel
  • ****
  • Posts: 492
    • View Profile
Re: [Bug] Melee attack hits terrain instead of unit
« Reply #3 on: August 25, 2024, 01:48:46 pm »
If I'm hitting the wall, then why does the hit log register misses? I mean, in practice, I don't know whether I'm hitting the wall or not. So it would be helpful if the log only registered attacks when I was actually attacking units and not terrain (like it usually does).
« Last Edit: August 25, 2024, 02:06:05 pm by Delian »

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9077
    • View Profile
Re: [Bug] Melee attack hits terrain instead of unit
« Reply #4 on: August 25, 2024, 02:05:43 pm »
If I'm hitting the wall, then why does the hit log register misses? I mean, in practice, I don't know whether I'm hitting the wall or not. So it would be helpful if the log only registered attacks when I was actually attacking units and not terrain (like it usually does).

Because the hit log is one giant hack, it's a miracle it works at all.

If someone can implement a better one, go for it.
I can't.

Maybe I can do the opposite, make it register also (melee only) terrain hits, not sure if that makes it better or worse.

Online Delian

  • Colonel
  • ****
  • Posts: 492
    • View Profile
Re: [Bug] Melee attack hits terrain instead of unit
« Reply #5 on: August 25, 2024, 02:12:13 pm »
You call it a hack, but I call it super useful haha; So many times it saved my ass because when I'm unable to play the game with sound, I can check the log whether the melee attack hit or missed. Well, this specific case is an obscure bug/feature, so I suppose it's not a big deal if it's left as it is.

I don't know much about loftemps and the 3d engine stuff. Could I ask for a short explanation on why the center of the enemy is determined to be voxel (8,8,11)? Or rather, why is the voxel (8,8,11), which should normally be right at the center of the enemy, positioned so low on those screenshots?
Also, normally you'd be able to fire at this enemy, so it's a bit strange that you're not able to melee attack it, despite the majority of its voxels not being obstructed.
« Last Edit: August 25, 2024, 02:20:27 pm by Delian »

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9077
    • View Profile
Re: [Bug] Melee attack hits terrain instead of unit
« Reply #6 on: August 25, 2024, 02:24:27 pm »
You call it a hack, but I call it super useful haha;

I didn't say it's a cheat.
I said it's a hack: https://www.merriam-webster.com/dictionary/hack (6a: a usually creatively improvised solution to a computer hardware or programming problem or limitation)


I don't know much about loftemps and the 3d engine stuff. Could I ask for a short explanation on why the center of the enemy is determined to be voxel (8,8,11)? Wouldn't it usually be something like (16,16,24)?

(16,16,24) is the size of the whole tile, voxels go from (0,0,0) to (15,15,23). (8,8,11) is roughly in the middle of that range.

Calculation for melee target voxel is:
Code: [Select]
int height = _target->getFloatHeight() + (_target->getHeight() / 2) - _parent->getSave()->getTile(_action.target)->getTerrainLevel();
_voxel = _action.target.toVoxel() + Position(8, 8, height);

Also, normally you'd be able to fire at this enemy, so it's a bit strange that you're not able to melee attack it, despite the majority of its voxels not being obstructed.

Shooting tries more than just one target voxel.

Online Delian

  • Colonel
  • ****
  • Posts: 492
    • View Profile
Re: [Bug] Melee attack hits terrain instead of unit
« Reply #7 on: August 25, 2024, 02:42:13 pm »
Hmm, I must be misunderstanding something. Shouldn't the center (voxel 8,8,11) of the target be be like on this screenshot?

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9077
    • View Profile
Re: [Bug] Melee attack hits terrain instead of unit
« Reply #8 on: August 25, 2024, 03:18:31 pm »
No.

The bottom of the unit is completely obstructed by the terrain (normally just by the floor; in this case even more by the northwall).
And there is also no perfect center, because there is an even number of voxels in the z dimension (24), so it's even lower, because of math/rounding.

The x and y dimensions of a tile are also even (16), so they don't have a perfect center either.
Depending on the case, it's either slightly to the left or slightly to the right (of your imaginary infinitely thin center line).

Online Delian

  • Colonel
  • ****
  • Posts: 492
    • View Profile
Re: [Bug] Melee attack hits terrain instead of unit
« Reply #9 on: August 25, 2024, 03:47:49 pm »
Ok, now I get it. Problem solved I suppose.