How can I make a 1d constraint for a part

  1. What do you want to achieve? Keep it simple and clear!

I want to make a cart in a cart ride game that does not allow the cart to be flung off the map.

  1. What is the issue? Include screenshots / videos if possible!

The issue is that I need the cart to only move in one dimension and not be physically able to change position in the other two dimensions.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have tried adding a part under the cart to keep it straight in the z axis (the cart moves only along the z axis, yes I know it is boring but I need it to be like this) this worked but when you rammed into something backwards you will be flung and the cart is very shaky, I have also tried placing a part welded to the cart under the map to keep it constrained but this leads to more shaking (and yes, there is still the shaking problem with both).

I have tried adding a part under the cart to keep it straight in the z axis (the cart moves only along the z axis, yes I know it is boring but I need it to be like this) this worked but when you rammed into something backwards you will be flung and the cart is very shaky, I have also tried placing a part welded to the cart under the map to keep it constrained but this leads to more shaking (and yes, there is still the shaking problem with both), I have also tried using a script to do this but it leads to very choppy motion.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

All I really need is a simple script that only lets the parent model (which does have a primary part) move in a certain direction eg.(forward and backward only, left and right only)All I really need is a simple script that only lets the parent model (which does have a primary part) move in a certain direction eg.(forward and backward only, left and right only), here is the code for movement if anyone recommends to use tweenservice because I do not know how to use it very good

function blow()
	for i = 1, 4 do
		if script.Parent:FindFirstChild("Engine") ~= nil then
			local ex = Instance.new("Explosion")
			ex.Position = script.Parent.Parent.Engine.Position + Vector3.new(math.random(-3, 3), math.random(-3, 3), math.random(-3, 3))
			ex.BlastRadius = 1
			ex.BlastPressure = 1000
			ex.Parent = game.Workspace
			wait()
		end
	end
	wait(1)
	script.Parent.Parent:remove()
end

script.Parent.Parent.ChildRemoved:connect(blow)
ms = 100


while wait() do
	
	if script.Parent.Parent.CarOn.Value == true then
		local look = script.Parent.CFrame.lookVector*script.Parent.Parent.Speed.Value
		script.Parent.LinearVelocity.LineVelocity = script.Parent.Parent.Speed.Value
		else
		script.Parent.LinearVelocity.LineVelocity = 0
	end
	if script.Parent.Parent.Speed.Value > ms then
		script.Parent.Parent.Speed.Value = ms
	elseif script.Parent.Parent.Speed.Value < ms*-1 then
		script.Parent.Parent.Speed.Value = ms*-1
	end
	
end

and yes, I know the code is horrible, I just used the default cart ride script and changed it to work with a linear velocity.

1 Like

Why don’t you just move it with code in your own way following nodes?

2 Likes

what do you mean by following nodes?

2 Likes

A single direction travelling cart would be very similar to a moving platform.
Just use a PrismaticConstraint. It allows whatever it’s connected to to travel in a straight line. You can set it to Servo or Motor depending on your needs.
You can make it so the cart wheels are cancollide off so they don’t even need to touch the track.

Here’s a tutorial model I made up for people asking about it:

*** EDIT **
I just reread your doubled up post. It originally says you only want something to work in one direction, but later says you want it to work in 2 dimensions.

You may want to edit your first post to get rid of all the double sentences, and then clarify if you need something to work like a cart or a platform.

I’ve also posted tutorial train models on a bunch of other peoples posts asking about trains and carts. You should use the Search button up top to check them out. Just search ‘train tutorial @Scottifly’ to check them out.

1 Like

I am currently trying prismatic contrainst, will get back if it works

1 Like

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