Hinge vehicle balance

Post Reply
Killpippo
Posts: 7
Joined: Sat Feb 01, 2020 10:40 am

Hinge vehicle balance

Post by Killpippo »

Hello,
before my questions, let me spend a word of appreciation about this forum and the people that contribute to help with their answers.

I'm implementing vehicles based on btHinge2Contraint. Throttle is simulated by btHinge2Contraint::setTargetVelocity on the wheel free axis.
I'm finding quite challenging to balance the various attributes (mass, gravity, angular velocities) in order to have an enjoyable control of the vehicle:
1) hard to avoid wheelie effect when suddenly change throttle direction
2) lowered by a lot the mass center to increase stability while turning, but when the vehicle is rolling (for example due to an explosion) the visual effect is awful
3) hard to apply the correct friction to have enough grip and allow a bit of enjoyable drifting

I uploaded a couple of video to show the problem 1) which is the most annoying.
tank, six hinges links cylinder colliders:
https://youtu.be/TupH95_XmuY

car, four hinges links cylinder colliders:
https://youtu.be/whVY2H-4zfM

For 1) I'll try to apply the velocity progressively and I'm tempted to apply some corrective impulses based on the body orientation.
For 2) and 3) I would appreciate if you can share an approach to the problem. I'm actually just playing with the numerous parameters without an effective strategy.

Thank you
User avatar
drleviathan
Posts: 698
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Hinge vehicle balance

Post by drleviathan »

Car race-em games often require very tuned "game physics" (as opposed to "accurate physics") in order to make them fun. The example for this I usually give is: crashes. Accurate car crashes happen quite fast: you're in control when suddenly the vehicle is tumbling faster than you can understand which direction is "up". This is why many car race-em games slow down the crashes and introduce non-physical control forces (magic torques and sky hooks): the player has time to react and can get more thrill from the crash rather than pure bewilderment. The game designers introduce non-physical logic such as:

(a) artificially high gravity while vehicle is "on the road" --> more friction less sliding
(b) suddenly reduced gravity when vehicle is "airborne" --> longer, slower jumps
(c) suddenly increased inertia tensor when vehicle goes into a crash --> slower tumbling
(d) suddenly introduce extra sky hooks when vehicle is airborne or in a crash --> some control over tumbling

Increased gravity would definitely help reduce wheelies but might make jumps and drops too fast --> you might be forced to make gravity dynamic to keep it fun.

An increased inertia tensor would help you keep your vehicles from doing wheelies, however it would also cause them to be harder to turn and harder to slow down when already turning.

Dunno about tuning sliding to make it more fun. I'm guessing it would be affected by all other tunings: gravity, inertia tensor, mass, etc will all influence the final sliding behavior. Maybe first tune for tumbling and all other things, and then introduce a dynamic friction knob on the wheels that is driven by some other measurements (some formula of speed and radius of turn).

Good luck.
Killpippo
Posts: 7
Joined: Sat Feb 01, 2020 10:40 am

Re: Hinge vehicle balance

Post by Killpippo »

(a) artificially high gravity while vehicle is "on the road" --> more friction less sliding
(b) suddenly reduced gravity when vehicle is "airborne" --> longer, slower jumps
(c) suddenly increased inertia tensor when vehicle goes into a crash --> slower tumbling
(d) suddenly introduce extra sky hooks when vehicle is airborne or in a crash --> some control over tumbling
All valid and inspiring suggestions.
Already just applying a force on an imaginary pole, proportional to the angle change speed, gives better result.
stabilizer.png
stabilizer.png (3.39 KiB) Viewed 1649 times
Also it could be not needed to calculate each frame if this is applied as an impulse.

I just need to take in consideration the general speed and disable when wheels are not touching.
Killpippo
Posts: 7
Joined: Sat Feb 01, 2020 10:40 am

Re: Hinge vehicle balance

Post by Killpippo »

After few attempts, I found a cheap but effective solution:
- calculate the desired vertical alignment.
- calculate the cross product with the actual vehicle alignment
- apply a torque, modified by a configured value, with the vector calculated above

Code: Select all

	btVector3 vehicleUp(
		_transform.getBasis()[0][TransformConstants::upIndex],
		_transform.getBasis()[1][TransformConstants::upIndex],
		_transform.getBasis()[2][TransformConstants::upIndex]);
	btVector3 vehicleForward(
		_transform.getBasis()[0][TransformConstants::forwardIndex],
		_transform.getBasis()[1][TransformConstants::forwardIndex],
		_transform.getBasis()[2][TransformConstants::forwardIndex]);

	// the expected up depends on the gravity implementation
	btVector3 stableUp = _transform.getOrigin().normalized();
	
	btVector3 torqueVector = stableUp.cross(vehicleUp) * _stabilizerFactor;
	
	// project the torque to the vehicle forward to ignore the pitch stabilization and deal only with rolling
	//torqueVector = vehicleForward * vehicleForward.dot(torqueVector);
	
	_body.applyTorque(torqueVector);
The advantage of this solution, over the limited performance impact, is it works good enough even with violent turns.
https://youtu.be/HVM3Xihsnw0
In my prototype case, I deal with a spherical world, so the expected up vector is approximated by the vehicle position direction.
For a plane world, it can be simple considered the absolute up vector.
But, for a prettier result, it should be taken in consideration the ground nature, by storing an analyzing the wheel alignment and their collision results.

For the general vehicle stability, it still remain the position of the gravity center the most effective source of stability
Post Reply