100% Physics Based Cart System [V2.0 Update]

Just use a mesh part of the new model you want to use, then use a weld constraint to that connecting to the “Base” part of the original cart, then make everything else invisible.

Great system. I’m not a scripter ( I’m a modeler ) and I’m looking to use this, I have imported it however I am having issues with collision groups. Is there an open source script to select a folder and It automatically sets the collision groups? As of now it just falls directly through the track!

This can really be made to a new game! thats awesome
and with better models and meshes that would looks so good

This is incredible! I’m going to use this just to learn how to accomplish a physics system in the future, thanks

Great system! However I’m having trouble finding a way to keep the cart on the rails the entire time at high speeds. Anybody have any ideas that might help me?

As @stravant said, you can add wheels under the tracks and make the Collision group for those only react with the rails.
I made a model for someone else that I’ve modified with tilting/turning bogeys for up and down hills, centering wheels to keep the train wheels centered on the rails, and wheels underneath the rails to keep the carriages from flying off the rails.
For a cart system that needs to climb steep slopes you may want to add a PrismaticConstraint and a spring to keep the wheels underneath the rails tight against the rails so the driving wheels don’t lose traction.
I use Collision groups to make it so the under wheels and centering wheels only collide with the rails and not the ties, Parts, or Terrain underneath the rails.
Here’s a link to a post with my model in it: How to make a train bounce up and down? - #2 by Scottifly

1 Like

This would be so good for a Minecraft type game or any resource gathering and building game not just those “Ride a cart to X” games.

All your work for the ROBLOX is awesome and so useful thank you Stravant!

Just a note on this, one of the goals I design into my cart systems is deliberately not staying on the tracks as aggressively as possible. There’s lots of ways to make a very robust cart system where it’s almost impossible to fall off but I feel that that kills a lot of the potential entertainment value so I try to find a good balance instead.

5 Likes

Is this system under any licenses or am I free to use it with credit?
and another question, what would be the best way to destroy the cart if no one has sat in it in a few seconds to prevent spam?

2 Likes

Awesome system! Thanks for sharing this.

I just wanted to add that the gamepad input wasn’t working for me. Apparently ‘UserInputService:GetKeysPressed()’ doesn’t return gamepad keypresses.
To fix it I added the following code after the ‘GetKeysPressed’ loop on line 138 of the ‘LocalCartUI’ localscript:

-- Handle gamepad inputs
for _, inputObject in pairs(UserInputService:GetGamepadState(Enum.UserInputType.Gamepad1)) do
	local direction = DIRECTION_FOR_KEY[inputObject.KeyCode]
	if direction then	-- ':GetGamepadState()' returns all states, and we only want the two triggers
		keyBasedThrottle += direction * inputObject.Position.Z	-- Throttle depends on how far we're holding (value between 0-1)
		isKeybasedDriving = true
	end
end

Might not be the best solution? But from my testing it seems to work…

1 Like

Was fiddling with this since it would be cool to use, but stuck one one small little problem

Is there a way to make a dummy cart, it wont take in any input, but still gets treated as a cart, example, another cart couples and still pulls it around

Tried removing all speed calls and bits, left coupling, but it just gets, heavy, and wont move at all.

I used two cars in my example, I just put an equal driving force in both cars.

Does abandoned carts despawn after a certain amount of time?

Big update!

V2.0 Changes

  • Carts now have an improved dashboard with a speed display and iconography.
    image

  • Now uses modern CollisionGroup names rather than legacy CollisionGroupIds.

  • Driving is now dynamically juggled between client / server depending on whether someone is riding in the cart for better responsiveness of the controls.

  • Controls now handle clicking ClickDetectors for switches and stuff underneath the throttle control better. Switching a switch will never interrupt your throttle setting anymore, clicking the switch will take priority.

  • Along with this switching switches pointing the wrong way when going through them is now done temporarily on the client in addition to being one on the server so you can go backwards through a switch as fast as you want without crashing.

  • Improved cart handling / acceleration at low speeds.

14 Likes

Added some new track sections to the place / set model (diagonal switches + diamond crossing):

10 Likes

Sorry to bother, but my carts keep falling off the track since I’m using the older track models, but I’ve edited the rails CollisionGroup to work with your cart. I’ve tried to fix this by moving the physical models (not the “visual” ones) they just go back to normal in-game and make the visual wheels look weird. How can I keep the physical models in the same position?

Images:

Why does the cart stay at 50 and -50 every time I use the W and S keys and it doesn’t speed up?

Captura de pantalla 2023-09-13 161255

same issue here… and most of my players are on mobile so it’s kind off annoying, really hope someone could provide a fix.

I suggest this Puglin, it does not have the effect when you brake but it is a good thing, the bad thing is that it costs 125 robux but it is seriously worth it!!

Why is this happening?

1 Like