fix(picker): lift sphere centre to mid-body so chest/head clicks hit

User reported intermittent selection — 'sometimes can be selected,
sometimes not'. Cause: WorldEntity.Position is at FEET level (Z=ground
for standing humanoids), so a 0.7m sphere centred there only covered
the lower legs. Clicks on chest (Z≈1.2m) or head (Z≈1.7m) missed
because the closest-approach distance from the cursor ray to the
feet-centered sphere exceeded the radius.

Fix:
  - Sphere centre now defaults to position.Z + 0.9 m (humanoid
    mid-body). New optional verticalOffsetForGuid callback overrides
    per entity.
  - Default radius bumped 0.7 → 1.0 m to match the new sphere
    placement (1.0 m at 0.9 m height covers a 1.8 m humanoid from
    shin to top-of-head).

GameWindow.PickAndStoreSelection wires the callback:
  - Creatures (ItemType.Creature flag): vz = 0.9 m (humanoid centre)
  - Large flat objects (BF_DOOR | BF_LIFESTONE | BF_PORTAL |
    BF_CORPSE): vz = 1.0 m + radius 2.0 m (mid-door/lifestone)
  - Everything else (ground items): vz = 0.2 m (just above feet)

Existing 9 WorldPicker tests still pass — their head-on ray geometry
doesn't depend on the vertical offset.
This commit is contained in:
Erik 2026-05-15 07:23:41 +02:00
parent 23cb1e9636
commit 1a0656a3ce
2 changed files with 51 additions and 8 deletions

View file

@ -9009,7 +9009,28 @@ public sealed class GameWindow : IDisposable
const uint LargeFlatMask = 0x1000u | 0x4000u | 0x40000u | 0x2000u;
if ((odf & LargeFlatMask) != 0) return 2.0f;
}
return 0.7f;
// 1.0 m sphere centred at chest height (see
// verticalOffsetForGuid) covers a 1.8 m humanoid from
// shin to crown without overlapping neighbours.
return 1.0f;
},
verticalOffsetForGuid: g =>
{
// Lift the pick sphere to mid-body so chest/head clicks
// hit instead of missing past the top of a feet-anchored
// sphere. WorldEntity.Position is at feet level
// (Z=ground); humanoids reach ~1.8 m, items sit close
// to the ground (~0.2 m above their feet).
if (_liveEntityInfoByGuid.TryGetValue(g, out var info)
&& (info.ItemType & AcDream.Core.Items.ItemType.Creature) != 0)
return 0.9f; // humanoid mid-body
if (_lastSpawnByGuid.TryGetValue(g, out var s)
&& s.ObjectDescriptionFlags is { } odf)
{
const uint LargeFlatMask = 0x1000u | 0x4000u | 0x40000u | 0x2000u;
if ((odf & LargeFlatMask) != 0) return 1.0f; // mid-door
}
return 0.2f; // small ground item — sphere just above feet
});
if (picked is uint guid)