I’ve been trying to get a moving platform to work properly using both PrismaticConstraints and AlignPositions, but regardless of what I do after about 15 seconds or so the character randomly falls off and can’t get back on again. (Video below)
Does anyone know why this might be happening? Thanks in advance.
Code:
local tweenService = game:GetService("TweenService")
local part = workspace:WaitForChild("Part")
local attach0 = Instance.new("Attachment")
attach0.CFrame = CFrame.new()
attach0.Parent = part
local attach1 = Instance.new("Attachment")
attach1.CFrame = part.CFrame
attach1.Parent = workspace.Terrain
local pris = Instance.new("PrismaticConstraint")
pris.ActuatorType = Enum.ActuatorType.None
pris.Attachment0 = attach1
pris.Attachment1 = attach0
pris.Speed = math.huge
pris.Parent = part
part.Anchored = false
tweenService:Create(attach1, TweenInfo.new(10, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true), { CFrame = part.CFrame * CFrame.new(0, 0, 100) }):Play()
^ As you can see, it works fine for a few seconds and then suddenly stops working completely.
I’m making a platform system that follows a path calculated using A* pathfinding and bezier curves to smoothen the movement, I guess the closest thing you could compare it to is a ship/train system. I used EgoMoose’s Platformer movement as a reference. (Platformer movement - Roblox)
Ah, k.
You don’t want to CFrame a Part and expect a player to stay on it, unless you weld the player to the platform.
Since you’re using a bezier curve system then you can’t use a PrismaticConstraint, unless you use 2 of them and move one on the X axis with it attached to another on the Z axis.
Yeah that’s why I avoided using CFrames, CFraming the attachment should work and it does but only for about 15 seconds before it suddenly stops working. It drags me along perfectly fine using the setup I presented in my original post but doesn’t work for long.
Before this I was “welding” the character to the moving parts similarly to Tyridge77’s train system by setting the HRP’s CFrame to that of the relative position between the object and player, but the downside of that is that other plays “lag” behind due to delay in replication, the higher the ping the further they lag behind.
You said it follows a path, but mentioned bezier curves. I only see the Part moving in a straight line.
You can change the PrismaticConstraint’s LinearResponsiveness to damp the movement.
Oh the video was just to demonstrate the issue, it happens regardless of the direction or speed. I was trying to fix the issue on a smaller scale first by having a part just move on one axis.
I have, the issue is that I can’t do it the way you did because the part has to follow a strict pre-defined path, hence why in my example I tweened it because it repeatedly updates the goal position, as it would in the full system I have prepared that do involve curves and pathfinding. I am creating a ship system that people can stand on to sail around that follows either a manually created path or one it automatically creates during runtime using A* pathfinding, and it smoothly sails along it using n point bezier curves.
The image below shows the path markers for my test setup it’d have to follow, while smoothly interpolating between them using said curves.
Okay, I figured it out, the issue seems to have been that the network ownership was automatically set to the nearest player after a few seconds, which completely halted the physics updates of the object. I used :SetNetworkOwner(nil) and it worked. Thanks everyone.
Well I am using the code you shared with badcc and us in the aforementioned thread, it works perfectly fine for the local player (aka your client) but other players still jitter due to replication delay. I had issues “welding” other players to the platform locally as specified in the quote below, probably because I misunderstood it. If you have time, could you elaborate on it?
For anchoring other players, it’s a tiny bit harder but still pretty straight forward.
We essentially have a relative cframe from the center of the train car on the server and, after trains are cframed, have your client take that info, loop through other players and if they’re on a train then set their hrp.cframe to trainroot * relativecframe(the one sent from the server)