Why does BridgeDropProcessing.GetDropPositionAndRotation invert the x and z parameters of the ItemDropPositionOffset?

airoll

Member
I'm reading through the code for GetDropPositionAndRotation (I think the spelling of this needs to be fixed by the way, it's missing the d in "And"), and I'm not really sure I understand why we are negating dropPositionOffset.x and dropPositionOffset.z, and also InverseTransformDirection instead of InverseTransformPoint?

C#:
        /// <summary>
        /// Get the drop position and rotation.
        /// </summary>
        /// <returns>Tuple of the position and rotation.</returns>
        private (Vector3, Quaternion) GetDropPositionAndRotation() // @CustomCode: Fix spelling.
        {
            var dropPositionOffset = m_InventoryBridge.ItemDropPositionOffset;
            var characterTransform = m_InventoryBridge.transform;

            // Spawn the inventory pickup, remove any children it has and place the drop prefab as a child.
            var localOffset = characterTransform.InverseTransformDirection(new Vector3(-dropPositionOffset.x,
                dropPositionOffset.y, -dropPositionOffset.z));

            var position = characterTransform.position + localOffset;
            var rotation = characterTransform.rotation;
            
            return (position, rotation);
        }
 
You're absolutly right I don't know what I was thinking at the time.

Here is the new code, I tested it and it works as expected
Code:
/// <summary>
/// Get the drop position and rotation.
/// </summary>
/// <returns>Tuple of the position and rotation.</returns>
private (Vector3,Quaternion) GetDropPositionAndRotation()
{
    var dropPositionOffset = m_InventoryBridge.ItemDropPositionOffset;
    var characterTransform = m_InventoryBridge.transform;
    
    // Local space offset to world space point.
    var position = characterTransform.TransformPoint(dropPositionOffset);
    var rotation = characterTransform.rotation;
    
    return (position,rotation);
}
 
Top