Train Controls Using Vector Force

Hello all,
I have a question on how I could make some controls using a vector force for a train? I am using a vector force to move the train forward and backward but I would like to have some more realistic controls instead of just a throttle. In trains here in the UK, the trains have a reverser (Whether the train should move in a forward, neutral or backward direction), power positions (1-4) and braking positions (1-3 and 4 being emergency.). The reason I am asking this question is because a vector force is the target speed, but using power positions isnt a set speed example position 3 != 60mph, its the rate of acceleration.
Thanks!

1 Like

If you don’t want it to be code, why did you put it in scripting support?

Because:

  1. Asking for code is not advised.
  2. I’m not learning how to code it if its just given to me.
  3. Because I’m trying to script it.
1 Like

My apologies, I thought you meant you didn’t want to code it at all. You didn’t want to use code.

One thing to note about VectorForces is that they have no limits. If you accelerate it will continue forever going faster and faster into oblivion, if you don’t have an existing way to control it, you may want to script the train’s movement manually. Using VectorForces to achieve a target speed will give you that speed for a moment, but it will not stop there, it will keep going.

1 Like

When I use the VectorForce, for example 1000, it goes up to a certain speed, but then stabilises at that speed. Sort of acting like a target speed/throttle instead of a power system.

1 Like

Try using LinearVelocity, and setting the .MaxForce really low, so it takes a while to get to the target speed.

2 Likes

I will try in roughly half an hour, I am not able to load roblox studio at this moment. I’ll let you know with results!
Edit:
It seems to have the same performance as my VectorForce. A velocity of 1000 keeps it at a constant speed. I guess what I am trying to say is to have an arbitrary number, and that number determines how much acceleration there should be.

2 Likes

I guess one solution I could do would be to add force constantly and remove force constantly based on the speed and power position. So if I want to move forward at power stage 1, I do Force += ForceOfStage1/Speed or something like that, I’ll plan to equation later. This is just to give an example. I wonder if it was just that simple all along.

1 Like

The force already determines acceleration as acceleration is equal to force divided by mass. When the train stabilizes at a certain speed, that is because the forces acting against it (presumably friction) are equal to the VectorForce and they cancel out. The solution you gave here could work well as it would account for any other forces.

2 Likes

Thank you for the reply! I have attempted to implement that, however when my coroutine is called, and I set the reverser to forward, I get immediately killed and the train has vanished. I thought it was something to do with the force being 0 but that does not seem to be the case. Force seems to be not a number for some reason.

This can happen if there is a division by zero somewhere. You can get around this by doing

if force ~= force then
    force == Vector3.zero
end

Which will set the force to 0 if it is not a number (assuming force is a Vector3)

Force is an integer. Im doing my calculations only on Force.X. The issue I am having is because of the wheel speed. Do you know how I could get the cylinders rotation speed? When I use AngularVelocity, if the wheel goes around a corner, the X axis is now the Z axis. Is there a simple way to get its rotation speed?
Edit: I fixed the speed issue by adding a check for when the power position is 0. Just need to check for wheel speed.

If you do wheel.CFrame:VectorToObjectSpace(angularvelocity of wheel) it should give you it.