Character Jumping on Moving Part ( Roblox Physics ) Bug?

Hi there.
I am currently working on a cool little project, and are currently experiencing some physics issues.

I have written a code, that should keep the player on a moving platform even if they jump.

The issue is that after a certain time (around 45 secs - 2 min) into the simulation, the physics somehow bugs out, and makes the player character jump forward instead of keeping them in place.

The sample below is a fresh studio world with very little coding. While the code I have written is still WIP, I do not believe that it is caused by that, but may instead be a bug?
robloxapp-20230927-1907453.wmv (5.0 MB)
Sorry for the lengthy video, the action happens near the end

--Server Script
local Main = script.Parent
local shipMovementSpeed = Main:FindFirstChildOfClass("LinearVelocity")
shipMovementSpeed.VectorVelocity = Main.CFrame.LookVector*30

game:GetService("RunService").Stepped:Connect(function()
	local alignPosition = Main:FindFirstChildOfClass("AlignPosition")
	alignPosition.Position = Vector3.new(Main.Position.X,20,Main.Position.Z)
end)
-- WIP client script
local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')

local previousCFrame
local previousInstance

local Function
local Function2
local Function3

local activeStates = {
	Enum.HumanoidStateType.Jumping,
	Enum.HumanoidStateType.Freefall,
	Enum.HumanoidStateType.Climbing,
	--Enum.HumanoidStateType.Landed,
}
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {workspace.FloatingObjs}
raycastParams.FilterType = Enum.RaycastFilterType.Include

Function3 = function(instance)
	local model=instance:FindFirstAncestorOfClass("Model")
	local root
	if model then
		if model:GetAttribute("Ship") then
			root = model.PrimaryPart
		else
			Function3(model)
		end
	end
	return root
end

Function = RunService.Stepped:Connect(function()
	local character = player.Character
	if character then
		local humanoid = character:FindFirstChildOfClass("Humanoid")
		local rootPart = character.PrimaryPart
		local rayOrigin = rootPart.CFrame.Position
		local rayDirection = Vector3.new(0,-100,0)
		local raycastResult = workspace:Raycast(rayOrigin,rayDirection,raycastParams)
		if raycastResult and table.find(activeStates,humanoid:GetState()) then
			local currentInstance = Function3(raycastResult.Instance)
			if currentInstance then
				local currentCFrame = currentInstance.CFrame
				if not previousCFrame then
					previousCFrame = currentCFrame
					previousInstance = currentInstance
				end
				if currentInstance ~= previousInstance then
					previousCFrame = nil
					return--previousCFrame = currentCFrame + (currentCFrame.Position - previousCFrame.Position)
				end
				local Rel = currentCFrame * previousCFrame:Inverse()
				print( (currentCFrame.Position-previousCFrame.Position).Magnitude )

				previousCFrame = currentCFrame
				previousInstance = currentInstance
				rootPart.CFrame = Rel * rootPart.CFrame
			end
		else
			previousCFrame = nil
		end
	end
	if not Function2 then
		Function2 = player.Character.Humanoid.Died:Connect(function()
			Function:Disconnect()
			Function2:Disconnect()
			Function3:Disconnect()
		end)
	end
end)

Does it have to do with the way the character’s PrimaryPart tilts during a jump?
Maybe try firing the Ray straight down in World Space, not relative to the Player’s Orientation.

A character primary part is always facing upwards, unless flinged or something else.

1 Like

Hard to say, might be some weird physics ownership thing, could you provide a repro studio file?

Flat Terrain Test.rbxl (56.7 KB)

Edit: Ah yes, ownership gets transfered from server to client.

To anyone ever stumbling upon this thread. - I will update the scripts above, so they work really nice for any physic based moving model, when I’ve worked a bit more on my script. You can then fork them for your own project.

Status: Still working on the scripts…

Here is your 1st update … Model Position 0, 20.185, 0

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.