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)