Trying to make a smooth moving platform for my obby that moves players on it.
Tutorial Followed:
The problem I am facing that even if the ray is detecting the moving platform, sometimes or frequently the player is glitching out from the platform, can’t figure out why
The Local Script I am Using:
local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')
local PlayerChar = Player.CharacterAdded:Wait()
local RootPart = Player.Character:FindFirstChild("LowerTorso")
local LastCFrame
local Function, Function2, Function3
Function2 = Players.PlayerRemoving:Connect(function(PlayerLeft)
if PlayerLeft == Player then
Function:Disconnect()
Function2:Disconnect()
Function3:Disconnect()
end
end)
Function = RunService.Heartbeat:Connect(function()
if PlayerChar and RootPart then
local RayParams = RaycastParams.new()
RayParams.IgnoreWater = true
RayParams.FilterDescendantsInstances = {PlayerChar}
local RayCast = workspace:Raycast(RootPart.CFrame.Position, Vector3.new(0,-10,0), RayParams)
if not RayCast then
return
end
local Hit = RayCast.Instance
print(Hit, PlayerChar.Humanoid.Jump)
if Hit and Hit.Name == "Moving" and PlayerChar.Humanoid.Jump == false then
local Platform = Hit
if LastCFrame == nil then
LastCFrame = Platform.CFrame
end
local PlatformCF = Platform.CFrame
local Rel = PlatformCF * LastCFrame:inverse()
LastCFrame = Platform.CFrame
RootPart.CFrame = Rel * RootPart.CFrame
else
LastCFrame = nil
end
else
PlayerChar = Player.CharacterAdded:Wait()
RootPart = Player.Character:FindFirstChild("LowerTorso")
end
Function3 = Player.Character.Humanoid.Died:Connect(function()
PlayerChar = Player.CharacterAdded:Wait()
RootPart = Player.Character:FindFirstChild("LowerTorso")
end)
end)
Oh lol i just noticed, yeah tweened/lerped parts wont move unanchored parts with it, here id use an AlignOrientation and AlignPosition instead of lerps
Search the forums for moving platforms. There are already a bunch of posts about this.
A great way to do it is using PrismaticConstraints because they are physics based.
Here’s a tutorial type platform model I made just because there were a lot of people asking your same question.
Is the platform the anchored Part, or are you using an unanchored Part welded to a tweened anchored Part?
CFraming is horrible for platforms, but using the physics aspect of an unanchored Part the player is standing on welded to a tweened Anchored Part may help.
Sounds good.
If you decide to use the PrismaticConstraint method to move at a fast speed you may want to tweak the LinearResponsiveness to a lower number so the platform doesn’t instantly accelerate to it’s Velocity and throw the player off.