Hi all.
I've come across some older threads discussing this exact issue, but I seem to be missing something, which is why I’m starting this new thread. The problem I’m encountering is that object positions change when they’re attached to a parent object (e.g., transport, specific mounts, etc.). The position and rotation (among other things) switch from absolute to relative, based on the parent object. After reversing the latest game client, I found the following:
cg_object has multiple vmethods which calculates and translates position and rotation accordingly to parent (if one exists), but to summarize:
- Retrieve cmovement from cg_unit + 0xB0 + 0x8].
- Check if a parent exists (cmovement + 0x0] points to parent data, and cmovement + 0x10] holds the guid of the parent, along with other checks, but I’ll keep it simple).
- If no parent is present, use the location and rotation from cmovement + 0x20] (for position) and cmovement + 0x30] (for rotation).
- If a parent is present (this step is recursive), retrieve the translation/world matrix for it. Verify if the matrix was constructed by checking the pointer at parent_cg_unit + 0x1678] (offsets vary by object type). If the pointer is valid, it means a valid world matrix was constructed, indicating that the object has children attached.
- If the matrix is valid, perform the translation using the matrix, applying matrix4x4 (the parent matrix) * fvector3 (the child’s location).
I’ve replicated this logic externally, but I noticed that the positions are slightly off along the z-axis. Based on the above, I have two questions:
- Why is my position slightly off? Since the matrix also carries rotation information, am I missing something obvious or making an error (all offsets are current for version 11.0.2.56162)?
- (Bonus, but not necessary) Is there a way to calculate the absolute position without needing to pull the parent via guid? There seems to be promising data at cmovement + 0x0] when a parent is present.
Thanks in advance. Attaching an image for visual representation:
https://i.imgur.com/ACHtmGi.png