Let me give you a more concrete example. I’ll use CharMoveComp again. Here’s the code that controls the platform movement:
// Calculate new transform matrix of base actor (ignoring scale).
const FQuatRotationTranslationMatrix OldLocalToWorld(OldBaseQuat, OldBaseLocation);
const FQuatRotationTranslationMatrix NewLocalToWorld(NewBaseQuat, NewBaseLocation);
// We need to offset the base of the character here, not its origin, so offset by half height
float HalfHeight, Radius;
CharacterOwner->GetCapsuleComponent()->GetScaledCapsuleSize(Radius, HalfHeight);
FVector const BaseOffset(0.0f, 0.0f, HalfHeight);
FVector const LocalBasePos = OldLocalToWorld.InverseTransformPosition(UpdatedComponent->GetComponentLocation() - BaseOffset);
FVector const NewWorldPos = ConstrainLocationToPlane(NewLocalToWorld.TransformPosition(LocalBasePos) + BaseOffset);
I then do something similar in a Unity script:
// Get our current position relative to the floor's old transform
Vector3 oldFloorPos = lastFloorTransform.InverseTransformPoint(transform.position);
// Determine what our world position would be if we were on the same spot relative to the floor's current transform
Vector3 newFloorPos = currentFloorTransform.TransformPoint(oldFloorPos);
// Find out how much we need to move to that new relative position
Vector3 floorAnchorPositionDelta = (newFloorPos - transform.position);
_characterController.Move(floorAnchorPositionDelta);
Would this qualify as something I can use and share?