Train collision physics behave weirdly when humanoids are involved

I want to make it so my train doesn’t derail when it collides with a vehicle occupied by a player (while keeping it physics based). As far as i know, the train might be the one causing this problem.
Here’s how it behaves without a player seated:

^This is what I want to achieve when a player is in the vehicle

Here’s how it behaves with a player seated:

As you may have watched, the physics are smooth when it comes to collisions with empty vehicles but behave weirdly when the vehicles are occupied.
The train is powered by an invisible part that moves it towards the direction it’s facing:

while wait(.1) do
	local direct = script.Parent.CFrame.LookVector * script.Parent.Speed.Value
	script.Parent.AssemblyLinearVelocity = Vector3.new(direct.X,-5,direct.Z)
end

There are also constraints involved, which are hinge constraints that connect the bogies to the train.

Here’s what I’ve done so far:

  • set the density of the train much higher than the vehicles.
  • made gliders between the wheels that keep it on the tracks.
  • added bodyangularvelocities that keep the train from flipping.
1 Like

Check to see if your invisible part’s position changes when the train hits a car with a humanoid in it.

2 Likes

I believe the reason this happens is because the car is under the player’s network ownership (basically means the player’s client controls the car).

On the server, the train hits the car, but the client tells the server the car hasn’t moved, so the train impacts until the client realizes the car just got hit by a train.


I think the best way to fix this would be, on server code, giving the server network ownership of the car when the train hits it for a short period (without network ownership of the car, the car either doesn’t work or the controls are super delayed (depends on how your car code works)).

This would allow your car to accurately get the velocity of being obliterated by a train. One problem, there might be a slight jump when the car’s network ownership is changed. Shouldn’t be too bad though because being nailed by a train is distracting/similar.

Article on network ownership:

Function used to set network ownership:
https://developer.roblox.com/en-us/api-reference/function/BasePart/SetNetworkOwner


Also, to control the train, you might want to look into BodyVelocity(s). They basically make the part/assembly move at a specific speed (if the MaxForce is high enough).

3 Likes