So I posted not so long ago about how to get a player to stick/grip on a moving platform:
I managed to get it working using BodyPosition and BodyGyro on the moving platform.
Everything seemed to be working…I could move the player on top of a directional arrow button, and that button would move the platform by setting the Position
property of the BodyPosition object. I set this on a heartbeat whilst the button is being pressed, e.g.:
local targetVelocity = 5 -- Measured in studs per second.
local targetPosition = platformBodyPosition.Position
for _, direction in ipairs(directions) do
local offset = (targetVelocity * step) * direction
targetPosition = targetPosition + offset
end
platformBodyPosition.Position = targetPosition
When I first start moving the platform with the player on it, everything seems good (the player moves with the platform). But after a while I noticed the player slowly stops gripping the platform. The more I moved the platform back and forth with the player, the worse it eventually gets and the player starts falling off the button instead of staying on top of the button (which currently sits on top of the moving platform as shown in the screenshot)
Here are my settings:
local movingPlatform = platform.MovingPlatform
local platformBodyPosition = movingPlatform.BodyPosition
local platformBodyGyro = movingPlatform.BodyGyro
platformBodyPosition.Position = movingPlatform.Position
platformBodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
platformBodyPosition.D = 100
platformBodyPosition.P = 10000
platformBodyGyro.D = 500
platformBodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
platformBodyGyro.P = 3000
platformBodyGyro.CFrame = movingPlatform.CFrame
movingPlatform.Anchored = false
So whats causing my player to eventually start to fall of the platform as opposed to moving with it? Like I said it works perfectly to begin with. But then gradually gets worse.
Thanks, really appreciate any help anybody can provide.