Sign in to follow this  
dascandy

Making vehicles stick and unstick to the ground

Recommended Posts

I'm making a game engine for an RTS game, in which I'm trying to get the vehicles to follow a fairly realistic method of accelerating and breaking. Given an AI option I intend to add, this makes it possible for the vehicles to decide to drive up a steep cliff or to accidentally not make their braking distance. If they don't make the breaking distance before a cliff, they should fall off in a predictable way, bounce on the ground a few times and become stuck to the ground again. Other than that, they can be viewed as being stuck to the ground most of the time. How do you make this kind of logic? When do the tires become loose, when do they become stuck again and how do you make it follow the terrain in other cases? I have the "bouncy" physics mostly tried out except for handling the result of a collision with rotation against a surface, but that's just the last case. I haven't been able to get a "vehicle" to drive anywhere though. TIA, Peter

Share this post


Link to post
Share on other sites
There are two possible solutions that I can think of. One is to use a raycast vehicle. This is a vehicle which uses a ray for each wheel, to detect where the ground is in relation to the chassis. the wheels are then "bolted on" for animation purposes only.

The second is to get the vehicle to detect the angle of the ground it is on, and tip itself in that direction. If your game uses a hight map or is tile based, this would be quite easy.
Then you can simulate the problem of falling off of cliffs by turning off this feature, so the vehicle will just bounce and crash. Are you using a physics engine, or coding it all yourself?

Share this post


Link to post
Share on other sites
Quote:
The second is to get the vehicle to detect the angle of the ground it is on, and tip itself in that direction. If your game uses a hight map or is tile based, this would be quite easy.

It isn't but I was planning on making the World class handle this logic.
Quote:
Then you can simulate the problem of falling off of cliffs by turning off this feature, so the vehicle will just bounce and crash. Are you using a physics engine, or coding it all yourself?


Not using a physics engine, coding it myself. My main point is that I don't really know how or when to toggle the "stuck" bit. I'm also a bit dumbfound how to make a vehicle rotate up a steep cliff and how to determine where the wheels will be.

Given an intersection between two polygons:


/
/
/
/
/
/
/
----------/


(not to scale)

when it moves from the flat polygon to the angled one (ignoring everything but the wheel contact points) how do you make it move up the hill without stretching?

[edit]

Rereading that, it doesn't make sense. I was thinking about moving it up the hill by adjusting the Z-values (depth values) of the vehicle to make it move up. That doesn't work because the steeper the hill is the longer the vehicle will become. If not that, you could rotate the vehicle backward until it was on top of the world.

Then you get the problem with a 4-wheeled vehicle that it can be with only two opposing wheels on the ground, more or less unstable but probably tipping to one or the other side.

I'm just stuck to make it follow the ground properly.

Share this post


Link to post
Share on other sites
There are several levels of accuracy available here. The first question is as to the relative modulus of continuity of the ground. That is, is the ground 'smooth' enough to treat each vehicle as a point or is it necessary to treat the edges/wheels of the vehicles separately. Obviously, the former is the easiest to deal with.

If the simple case is adequate then you'll get away with simply orientating the vehicle according to the tangential slope of the ground at its midpoint. If this doesn't quite cut it then a second pass may be necessary to readjust the height of the vehicle after rotation so that the mean distance between the wheels and the ground is minimised. If even this doesn't produce convincing results then you can treat the (presumably rectangular-profiled) vehicle as a three-wheeler and orient the three wheels in the tangential plane of the ground. Failing this, you'll probably have to model the vehicle as a rigid body, which take a fair bit more work.

Share this post


Link to post
Share on other sites
Quote:
Original post by TheAdmiral
There are several levels of accuracy available here. The first question is as to the relative modulus of continuity of the ground. That is, is the ground 'smooth' enough to treat each vehicle as a point or is it necessary to treat the edges/wheels of the vehicles separately. Obviously, the former is the easiest to deal with.

If the simple case is adequate then you'll get away with simply orientating the vehicle according to the tangential slope of the ground at its midpoint. If this doesn't quite cut it then a second pass may be necessary to readjust the height of the vehicle after rotation so that the mean distance between the wheels and the ground is minimised. If even this doesn't produce convincing results then you can treat the (presumably rectangular-profiled) vehicle as a three-wheeler and orient the three wheels in the tangential plane of the ground. Failing this, you'll probably have to model the vehicle as a rigid body, which take a fair bit more work.


After having a year-end to think about it, I think the basic model is applicable - since you'll be viewing the world top-down you won't notice the wheels actually being below ground. Understeer and oversteer don't apply either, neither should occur. So, just move the vehicle forward, determine what happened and rotate the vehicle appropriately as if it was a single point. I think I can use the angle of movement (old point -> new point) as measurement whether it hit a cliff so I can make it stop then and I can use the angle as well for tipping over (sideways or backward) given a certain threshold angle and for the amount of momentum left for going forward.


Thanks for your answers and a happy new year!

Share this post


Link to post
Share on other sites
Quote:
Original post by dascandy
I think the basic model is applicable - since you'll be viewing the world top-down you won't notice the wheels actually being below ground.

Sounds good. If this does turn out to be a problem, you can probably fudge it with a little z-buffer trickery.
Quote:
Original post by dascandy
Thanks for your answers and a happy new year!

You're welcome, and likewise [smile].

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this