Components for making Vehicles

I’m attempting to create vehicles that move by themselves(a train, for example). However, I am not sure about how to move it smoothly. So far I am looking at BodyMovers.

I’ve tried using BodyForce, which works ok but the parts go over walls it should not go over. I’m also worried that there might be friction involved, slowing it down. Would HingeConstraints work for this?
I’ve also tried using BodyThrust, which sends the model flying even though I set the force to the Z direction. The force I used was 0, 0, 100000000

Any help would be appreciated.

First and foremost, it’s unlikely you’ll get a fully functional train without at least some level of scripting. I’m not entirely sure what your train needs to be able to do, so I’ll leave the majority of this to later replies.

From your post, it seems like you have some misunderstanding about how the BodyMover types you’ve tried work. Allow me to provide some insight.

BodyForces and BodyThrusts apply a constant force in the direction and with the strength you set. As such, your vehicle would keep accelerating forever, without a top speed. There are two key differences between the two:

  1. BodyForce always applies a force to the object’s center of mass. A BodyThrust allows you to set the location relative to the center of mass that the force is applied to.
  2. A BodyForce always applies its force in “world space”, i.e. if you set a force of (0, 100, 0), it will apply an upwards force of 100 units regardless of the orientation of the parent part. A BodyThrust applies its force in “object space”, i.e. that same force of (0, 100, 0) will always apply a force of 100 units towards the part’s top surface.

The most realistic way to make it work would be via a HingeConstraint with a Motor actuatuator type. You could use this to spin the wheels on your train and build some rails to guide it. This is ultimately how I’d suggest you do it.

A more commonly used and time-tested strategy is to use a BodyVelocity with a script looking somewhat like this:

--Configurable values
local speed = 32 --Twice as fast as a person can walk!

--Get the part and the BodyVelocity
local part = script.Parent
local bodyVelocity = part.BodyVelocity

--Get the Heartbeat event
local heartbeat = game:GetService("RunService").Heartbeat

--Repeat the following code forever
while true do
	--Set the BodyVelocity to move the part forwards
	bodyVelocity.Velocity = speed * part.CFrame.lookVector
	
	--Wait here and give Roblox time to do other stuff
	heartbeat:wait()
end

Hopefully this helps!

1 Like