Indiana Jones type mine carts and track problem...

Hi all,

I am trying to create a similar rollercoaster type game, with a cart following a track using waypoints.

However I want the cart to fly off the track if going to fast around a bend or over a hump etc?

Anyone got any ideas how to do this? all current waypoint examples I have used do not allow the cart to follow the track 100%, the curves created between the waypoints are to big?

Thanks in advance for any help…

Without code I can just take an educated guess. For following a track you can do one of two ways.

  1. Waypoint method: What you’re using, however you probably need them closer (as you guessed) And then track your speed using a bar or something (so that you have a visual comparison of speed), and if speed is at a certain level when you hit certain waypoints, have the cart roll off of the track. Having the waypoints closer will help in this respect too because then you can hit one way-point and then allow your cart to half-way tip (giving your player some time to react) and if it’s at the half-way tip and still going too fast, then allow the cart to push all the way off.

  2. RollerCoaster method: Like a rollercoaster, it uses a set of extra wheels to keep it on the track. These wheels can be invisible (You can also use box colliders in a rectangular shape), and if your cart does come off the tracks you’ll know.

Something like this for your wheel setup:

 __________
X X      X X
XOX      XOX
X X      X X
 |        |
 |        |
X X      X X
XOX      XOX
X X______X X

O = Wheels
X vertically = The rectangular (invisible) box colliders

I haven’t tried to do anything exactly like this myself, so I’m just speculating here. But, here’s what I’d probably try first if I were to tackle something like this.

As you noted, waypoints probably aren’t really an ideal solution here. What might be better would be a spline.

The nature of the spline is secondary, more or less (you could use, for example, a connected series of Bezier curves). The important part is that using a spline would allow you to position the cart (and the track geometry itself) with more or less perfect accuracy.

For moving the cart along the spline, you’d probably want to either use arc-length reparameterization, or ensure that the spline control points are such that constant speed in parametric space equates to nearly constant linear speed in 3-d space.

For ‘tipping’, you should be able to determine the ‘tipping force’ based on the cart’s speed and the curvature of the track at that point. Up to the ‘tipping point’ you could simply animate the cart tipping up on two of its wheels; past that, you could decouple the cart from the spline and let normal rigid body physics take over.

For ‘jumping’, you can determine whether and how much the cart should leave the tracks based on the current speed and, again, the curvature of the track relative to the cart. For small ‘cosmetic’ jumps, you could just animate the effect. For larger jumps, you could again put the cart in ‘rigid body’ mode. For landing, you could use normal rigid body motion and collision detection or a closest-point-on-spline test to determine if the cart has landed on the track (and with the proper alignment), and can resume following it.

There may be other ways to do it as well (for example, having a ‘virtual anchor’ follow the track and have the cart be attached to the anchor by a spring). Overall though I think a spline-based approach would likely be the way to go, as it would probably be difficult to get the cart to follow the track in a natural and realistic way using only rigid body physics.

Again though, I haven’t tried anything like this myself, so I’m just speculating.

Hi all,

I’m new to the forum!
I have the same problem…
I tried these solutions but don’t work.
Anyone know how to resolve it?
Please, I’m going crazy.

Thanks!
Francesco

Again, I probably have no idea, but I would make an invisible box collider with istrigger set to true. When the cart hits this box a script could check the speed of the cart and then if the speed is high enough, a variable, perhaps “isontrack” would = false. Then if isontrack = false, the cart could stop following the track and a force could be applied to make it fly off.

Sorry if I was no help.

Hm, haven’t seen this thread in a while…

For something like this, the implementation is going to be non-trivial no matter what, so I wouldn’t necessarily expect any solution to work perfectly the first time.

If you’re having trouble with your implementation though, you can always ask questions here. Just make sure your questions are detailed and specific (e.g. tell us what you’ve tried, describe how it’s not working, and post code if appropriate), as otherwise it’ll be difficult for anyone to help.