PDA

View Full Version : Need some help brainstorming a physics problem.


Backov
06-02-2007, 10:31 AM
So, I've finally got to the point where I'm tweaking my physics model (using PhysX) in my game to try to get the gameplay right.

My racer is a hovering/maglev racer driven by a big thruster on the back, and racing in a half-pipe. But, I want it to have a special property - that is, when you're turned away from your movement vector, you start to slow down.

Here's an image to illustrate:

http://tamedtornado.com/physicsprob.png

The red vector is your movement vector, the green is your heading.. As you can see, in a "zero-g" type of racer, he's going to slam into the wall. Unfortunately that makes for crap gameplay. I want him to gradually slow down if he's side-on to his movement vector.

Any ideas how I might accomplish this? I had thought of having 4 invisible wheels (that don't turn), but then I would have to lift the racer up to turn it.

The other solution I have tried is anisotropic friction, but it doesn't go high enough to stop the racer in any reasonable amount of distance.

Philippe
06-02-2007, 10:46 AM
Not familiar with PhysX, but how about applying an additional smaller thrust opposite to the movement vector with strength depending on the angle between movement and heading?

Ratboy
06-02-2007, 10:56 AM
Frontier: Elite II's basic flight mode used newtonian physics, but lit up the thrusters on the various sides of the ship in an attempt to keep the ship moving in the direction the nose was pointing. You could have it activate lateral thrusters to change your course. Say if you're floating along, and turn to the right, the left side thruster (and the main thrusters as well) would start pushing you until your new vector was lined up along your nose.

Backov
06-02-2007, 01:00 PM
Not familiar with PhysX, but how about applying an additional smaller thrust opposite to the movement vector with strength depending on the angle between movement and heading?

Ya, that's what I was originally going to do, but it seemed inelegant. I guess there's no good way to physically simulate a magical mag-lev field. :)

luggage
06-02-2007, 01:34 PM
Not sure if it's the effect you're looking for (or if the effect would actually work) but how about applying a force in the opposite direction to the craft's momentum? (the purple arrow). The larger angle "A" is the more that force needs to be. It would be maximum strength if the craft has turned through 180 degrees.

Just saw Philippe posted the same solution. That's reassuring.

Backov
06-02-2007, 02:41 PM
That does appear to be the best solution. I'll just make the cube the racer rests on near frictionless and see if I can get the code to work. Thanks for all the suggestions guys.

Anyone know how to convert a Quat to a heading vector? I don't. :)

Philippe
06-02-2007, 03:50 PM
Convert it to a matrix and take its z-axis (3rd column)?

Backov
06-02-2007, 04:27 PM
Convert it to a matrix and take its z-axis (3rd column)?

A friend told me that it's Vector = Quat * model facing (-UNITZ in this case)

jlv
06-02-2007, 07:59 PM
I would project the velocity vector to the x-axis of the vehicle, scale it by a small negative number and then apply that force to the vehicle. That would make the vehicle act like it has a stabilizer fin.

You might find the wikipedia fluid friction page helpful.

http://en.wikipedia.org/wiki/Fluid_friction

Therion
06-02-2007, 10:08 PM
Wait, i think i did this before...

My math sucks but maybe something like this in the racer's update loop can do the trick...

innertia = 0.9;

x += vx;
y += vy;

vx += get_xvector(angle, accel);
vy += get_yvector(angle, accel);

vx *= innertia;
vy *= innertia;


You have to limit vx and vy values to match the racer's max speed though.
maybe you can do something like this (i'm coding this now so don't take it literally :P)

if ( vx > get_xvector(angle, max_speed) )
vx = get_xvector(angle, max_speed);

if ( vy > get_yvector(angle, max_speed) )
vy = get_yvector(angle, max_speed);


Cheers!.

Jim Buck
06-10-2007, 09:19 PM
I was going to post it, but I see jlv already got it - it's called "viscous friction". I used this for the steering of vehicles in the PlayStation 1 game Rally Cross. Like jlv said, take the "X" (sideways) velocity, and the force vector is: F = -c*v, where "c" is your viscous friction constant and "v" is the sideways velocity.

Huge
06-10-2007, 10:04 PM
Yes, I don't think you want a special case for turning vs non turning, I think you want air resistance. How do you slow down normally? Is the "thruster" accelerating you, if so, what is there to balance the acceleration? How else do you get a "maximum speed"

Air resistance is simply a force in the opposite direction to your motion. You could make it proportional to v^2, to get the effect you are after. It might also depend on your profile, eg if you "bank" into the corner you would get more resistance and make it easier to steer.

I would think the the skill in driving the racer in a low friction environment would be to turn well past 90 degrees so you get some thrust pointing against the direction you are travelling. So maybe the solution is to have wilder, "overshoot" style steering, rather than forces to "help" too much.

Backov
06-10-2007, 11:44 PM
I actually implemented the opposite force by degree of angle difference thing and it works dandy. :)