I had a working method to keep something stable on a moving platform using CFrame. Now I need to apply the same logic to a model (like an airplane). At first, I tried calculating positions for every single part individually, but that caused so many bugs it became unmanageable. Now I’m trying to simplify by using GetPivot() on the model itself. But weirdly, the player still keeps falling off the plane like it’s not syncing properly. Any ideas what’s going sideways here?
Here is the script:
local rayOrigin = rootPart.Position
local rayDirection = Vector3.new(0, -10, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {character}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
local platformModel = nil
if raycastResult and raycastResult.Instance then
platformModel = raycastResult.Instance:FindFirstAncestor("Plane")
end
if platformModel then
local currentPlatformCF = platformModel:GetPivot()
if lastPlatformCFrame == nil then
lastPlatformCFrame = currentPlatformCF
end
local CF = currentPlatformCF * lastPlatformCFrame:inverse()
lastPlatformCFrame = currentPlatformCF
rootPart.CFrame = CF * rootPart.CFrame
print(rootPart.CFrame)
else
lastPlatformCFrame = nil
end
Using CFrame to move model/platform is not advised on Obby instances (Where you will have Players/Characters standing or even walking on top of the model/platform), instead use Physics Constraints for the movements.
Link - Mechanical constraints | Documentation - Roblox Creator Hub
Setting part.CFrame is equal to setting it to teleport into a set position and orientation.
[PS] If you encounter error such as the platform being clipping or it have collision issues to move properly as expected, set Part.CollisionGroup to right ones so it does not collide to its surronding but it is still colliable to Players.
Not really sure what you meant, as I do not see the model being moved by CFrame anywhere on your script given above.
There are a lot of potential explanations, but if you are moving a model with CFrame, make sure it’s Anchored parts in the model, and use Model: PivotTo().
^ Using :PivotTo(newCFrame) should work, unless your calculated newCFrame is incorrect in the script.
If it is supposed to be a movable un-anchored model, make sure it is welded to 1 single Root Part, and then set Root:SetNetworkOwner(nil) so model follows server-physics authority, and finally to move this unanchored model you just need to use one of the Constraints to mimic the movements etc.