#Help with a moving platform

1 messages · Page 1 of 1 (latest)

hollow dagger
#

Hi people can someone help me?

I got a moving platform using physics and i want to make a inertia for it so once i jump i dont get off the platform. I saw on forums that jailbreak train system post and tried to replicate that. It worked very well for tweening parts but bugs out for physics based movers.

I adjusted the code a bit to work better but there still some problems that happens. The code is:

if hitResult then
--checks if the player is jumping, falling down, climbing or in free fall
        if humanoidState[humanoid:GetState()] then
            
            if not lastPlatformCf then
                lastPlatformCf = platform.CFrame
            end
            
            local relCf = platform.CFrame * lastPlatformCf:Inverse()
            lastPlatformCf = platform.CFrame -- update the lastPlatformCf
            rootPart.CFrame = relCf * rootPart.CFrame
        else
            --resets if the localplayer is not jumping
            lastPlatformCf = nil
        end
    else
        --resets if the localplayer is not in the platform
        lastPlatformCf = nil
    end

Roblox handles the contact and the code runs only when player jumps, it works when the platform is in low/normal speed, whoever it bugs out and push the player foward at high speed.

if someone can help me out with this i appreciate.

Here both videos at normal and high speed

scarlet bear
#

Try applying a relative transformation to the players humanoidrootpart based on the platforms motion

#

it works way better for tweened platforms because their motion is deterministic and frame perfect

#

physic based movers like bodymover vectoirforce ect have inconsitencies

#

Use renderstepped over heartbeat or stepped because its synced with the camera and player movement

#

(local)

#

I would also avoid lastplatform Cf everyframe because it will cause misalignment if you jump right after stepping on it

#

or you could set it up like this

#

`local lastPlatformCf = nil
local runservice = game:GetService("RunService")

RunService.RenderStepped:Connect(function(dt)
local character = game.Players.LocalPlayer.Character
if not character then return end

local rootPart = character:FindFirstChild("HumanoidRootPart")
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not rootPart or not humanoid then return end`
#

and you can use raycasting to detect platform

hollow dagger
#

Oh ye im already using that, except running it on renderstepped

#

about the relative transformation

#

doenst this already does that?

            local relCf = platform.CFrame * lastPlatformCf:Inverse()
            lastPlatformCf = platform.CFrame -- update the lastPlatformCf
            rootPart.CFrame = relCf * rootPart.CFrame
scarlet bear
hollow dagger
#

heres the whole function tho mybad for not posting it all

local function syncPlayerWithPlatform()
    local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
    if not character then return end
    
    local humanoid = character:FindFirstChild('Humanoid')
    if not humanoid then return end
    
    local rootPart = character:FindFirstChild('HumanoidRootPart')
    if not rootPart then return end

    local rayOrigin = rootPart.CFrame.Position
    local hitResult = workspace:Raycast(rayOrigin, rayDirection, rayParams)

    if hitResult then
        --checks if the player is jumping, falling down, climbing or in free fall
        if humanoidState[humanoid:GetState()] then
            
            if not lastPlatformCf then
                lastPlatformCf = platform.CFrame
            end
            
            local relCf = platform.CFrame * lastPlatformCf:Inverse()
            lastPlatformCf = platform.CFrame -- update the lastPlatformCf
            rootPart.CFrame = relCf * rootPart.CFrame
        else
            --resets if the localplayer is not jumping
            lastPlatformCf = nil
        end
    else
        --resets if the localplayer is not in the platform
        lastPlatformCf = nil
    end
end
fiery violetBOT
#

studio** You are now Level 1! **studio

scarlet bear
#

hitResult.instance?

hollow dagger
#

no no is the instance im standing on

#

the raycast params only includes that platform

#

so no need to check if its the right one

#
local platform = workspace:WaitForChild('standingPlatform')
local runService = game:GetService("RunService")
local localPlayer = game.Players.LocalPlayer
 
local lastPlatformCf
local filteredInstances = { platform }
local humanoidState = {
    [Enum.HumanoidStateType.Jumping] = true,
    [Enum.HumanoidStateType.FallingDown] = true,
    [Enum.HumanoidStateType.Freefall] = true,
    [Enum.HumanoidStateType.Climbing] = true
}

local rayDirection = Vector3.new(0,-15, 0)
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = filteredInstances
rayParams.FilterType = Enum.RaycastFilterType.Include
#

the definitions

fiery violetBOT
#

studio** You are now Level 2! **studio

hollow dagger
#

its all running in the client as well

scarlet bear
#

are you trying to make it run multiplayer?

hollow dagger
#

Yes i have set one is just disabled atm

#

It send the positions to the server using instance values in the player character, so clients get the info from there and update it as well

hollow dagger
#

i changed to renderstepped too

#

before it was running with heartbeat. Doenst changed much tho

#

Is the inputs fine or there something i could change

hasty sparrow
#

bro

#

why u not just weldconstraint to platform ;-;

#

wat is this

hollow dagger
#

weld myself in the platform?

#

💀

hasty sparrow
# hollow dagger weld myself in the platform?

yes, while touching it keep humanoidrootpart weldconstrainted to the platform and for wasd integrate the positional movement unit vector difference to the part position on the weld constraint every render stepped. ts not rocket science ;-;

#

that way u will always move relatively to the part without a janky effect

hollow dagger