- Home /
Why does the train jump?
Hello everyone,
I'm trying to make a train that follows the track, but every single time, the wheels just jump out the track without an apparent reason.
I've already tried to set the collision detection to Continuous Dynamic, Continuous and the default one, Discrete, but they still jump out of it.
To make it displace itself, I add a force to the wheels, with the direction of the red rays you see in the video itself.
Is there a way to prevent this from happening?
Thank you, PeterAS17
You should not use actual physics for trains ( in my opinion atleast ), it would be better to fake it
What do you think would be better then? :) ($$anonymous$$nowing that I will have curves)
well, there can be a few ways to fake it, one way could be using a waypoint system, so that the train follows each waypoint on the track
@AngryBurritoCoder yeah, already thought of that way, but it wouldn't look as good as with physics in my opinion... that's why I'm asking for this method. Plus, with the waypoint system, stopping in stations would be harder to make I would say...
I agree about not using physics here - it's too low level - you'd want to use physics if something got in the way of the train, or if some boxes are balanced on top of the train. For moving it, use waypoints as suggested.
However, if you really want to use physics, try adjusting the mass of the train, and add/improve the dampening setup (basically suspension) to cushion it... but again I$$anonymous$$HO it's going to be a lot of effort to solve a problem that could be better solved a different way.
Answer by RayJr · Jul 02, 2015 at 01:36 PM
You can take the jitters out of it by adding angular drag. Add enough and the train will just sit still. You'll need to add more force to make it move again of course and will take some playing around to get the right balance. In fact, you might end up with a much more train like feel if you make it nice and draggy.
EDIT: I do agree with the guys above saying that physics might not be the best idea. But if you intend on crashing the train or want hills and things to affect it you'll want to stick with physics.
I did try adding some angular drag, but in most cases, it just made the train jump even more! :P
But I will try their method as well, to see how perfect it can be.
But just as I asked there, how can I make the train turn with the waypoint system??
It's somewhat of a manual process. Simply put, you add a bunch of objects along the track and then make the train move toward each one, in order, until it hits each one. After it reaches the first, move it toward the second and so on.
You can probably be sure that any train you've seen in a game isn't using the level of physics you're trying to accomplish here with the wheels and tracks.
If you wanted to stick with physics you could even try making the collider on the train a big rectangle along the bottom that sits flat on the ground. Then your track being two long (invisible) colliders that go on either side of the track. $$anonymous$$ake the train light and the 'tracks' really heavy and give the train force. Assign a material with low friction.
So (just to be sure), with the waypoints system, I have to make every single point for a curve, right?
Second, I didn't understand the method with the physics... even if that worked on a straight line, it would probably get stuck against corners, if it's an underground, because it's a cube collider...
For the curve, technically you could script it but making way points would be easier I would think.
You could also use a Nav$$anonymous$$esh and make the only walkable path the track. then you would only need waypoints at the end where you want the train to go.
For the physics, you could make the train collider a sphere, but lock the rotation so it doesn't fall over. I've never done something like this, but I don't think it's impossible. it would take some trial and error.
Nav$$anonymous$$esh system is working perfectly. Thank you so much for your help! :D (Thank you @AngryBurritoCoder and @n1ght as well! :) )
Your answer
Follow this Question
Related Questions
why does my train jump off the tracks? 0 Answers
2.5d Player Controller 0 Answers
Pushing a ball in a direction -1 Answers
Collision work on pc emulator but not on android device 0 Answers
Excluding Vertices from Cloth Colliders in Unity 5 4 Answers