Car racing - Physics

Posted By: Carloos

Car racing - Physics - 09/04/11 15:01

Hello.

I readed a lot yesterday in the forums, and I see there is a lot of topics about it, and some very confusing information.

I would like to ask you experts, considering the actual situation of the engine today, what would be the best choice to make car racing physics ?

How is the actual situation of Newton Dynamics ? And how is working the "embedded" 3dgs physics ?

Basically, what I have in mind is, a racing game, using some sort of physics Engine, but, also multiplayer.

I´m willing to offer a job to someone whit the knowledge ( and time ) to work on it to me, but, as I dont have too much money, maybe I would do it by myself.

I wrote, in the past, my self "physics" to race cars, and, with more or less sucess, it worked. I also worked with newton a bit, and got interesting results, but the speed achieved was not that great.

My last results with Newton, at that time were this :

Kart Racing - Newton Player + Newton AI

And the result of my attempt to write car physics was this one ( I made it a lil better after this video, but didnt have videos )

My own "car physics" in c-script

I would appreciate any suggest or comments.

Thankyou.
Posted By: 3run

Re: Car racing - Physics - 09/05/11 17:58

Looks good so far, you've made car physics with "c_move" right? And an other one with newton, right?
Posted By: Carloos

Re: Car racing - Physics - 09/05/11 19:43


Yes, I made car physics with c_move and so on.

The kart racing game was made with Newton, but was too unstable.

I want to get back to racing games, but I´m very confused about the improvments and changes on 3DGS, speccially PhisX and C-lite prossibilities.

Thx for replying.

Cheers.
Posted By: Progger

Re: Car racing - Physics - 09/05/11 21:33

Carloos im a big fan of you i really like your game and how you coded that car impressive :)As i saw it on youtube i was impressed laugh
Posted By: Carloos

Re: Car racing - Physics - 09/05/11 22:07

Thankyou, Progger.

You´re being very very generous in your reply.

In fact, I got happy at that time with my c_script physics, and I think I would get something nice if I got more time to keep working on it.

But, due to my lack of knowledge about collision and math, I stuck with collision at walls and other cars, then I gave up.

I wish I could made it complete, would be nice to achieve it, but its really very difficult to programm physics that way.

The nice part was, being the physics only calculated to the car movement, nothing else, it was very fast.

Now I need something reliable and fast enough to make something commercially able, and dont have so much time to do it.

I just bought an update to commercial, to make use of features like shadows and minimal shaders like reflection, and I´m hungry to get something showable fast.

One more time, thankyou for your very generous cumpliments.

Cya,

Carlos
Posted By: Carloos

Re: Car racing - Physics - 09/06/11 13:48

Mmmmmm

Well, it looks like the community isn´t so responsive like it used to be some time ago.

By this time, I managed to get a Physx car assembled in the engine, using a script I found at the forums, and was able to move it forward, altering the code. Turning it result in a spin, of course because the physics settings are only basic assembling proposed.

Would love to read something from more experienced users, maybe when they get some time ?

Cya.
Posted By: HeelX

Re: Car racing - Physics - 09/06/11 17:05

The amount of users which are using advanced physics (other than boxes and spheres) in their applications was always relative low. Since A8 introduced PhysX, I believe there are less people who try to work out car physics.

Given a physics engine, especially a realistic simulation can be achieved, while it is super hard to have full control over the vehicle from a programmers point of view - you have always sort of indirect control with a physics engine. Especially when you try to code AI opponents. If done sophisticated and with some experience you will get a robust vehicle (meaning that it doesn't flip all the time in curves) and last but not least, if you it well, due to the physics-approach it might be fun for the player, too.

If you do a script-based "physics"-simulation (with the c_) instructions, you have full control, but making a realistic simulation is a lot of work. Due to the full control, it is also very robust and programming becomes easier, just rethink about AI wink

But in all cases I doubt that a script based approach will be ever realistic and as long as you want to achieve that, you will better use a native physics-implentation for a vehicle, I suppose.

I am currently working on a PhysX-driven vehicle simulation, but

1) It deals only with one vehicle
2) It is a heavy vehicle and
3) It is a slow vehicle.

But nevertheless, I am confronted with much issues as well. One of the requirements is that the vehicle will brake and will stand still automatically, when no gas is used. That was more work for me to figure out how I should do this compared to build the whole physics setup and make it work (it is a vehicle with several constraints, an attached trailer and a different way of steering).

Nevertheless: especially on high speeds things become tricky. In commercial productions, like those F1 games (you showed a video of a F1 racing sim of your own), there is a lot of work put into making those physics simulations... in the end it is ALL ABOUT that physics simulation of the F1 cars. So, you might guess how much work is put into that and I suppose you need to do lots of work in order to achieve nearly the same with PhysX. Not because PhysX is bad, but because it is always hard work to achieve good & stable physics and physics, which are at the end fun as well.

So, short answer: Yes, I believe you can do modern, advanced car racing physics with PhysX in A8, but you will have to invest large amounts of blood, sweat and tears smile

...like in every game dev project wink
Posted By: Carloos

Re: Car racing - Physics - 09/06/11 17:33

Hi HeelX

Thankyou for your considerations.

I´m really losted... if I think only in satisfaction as a "programmer", I would stick with rewriting my physics again in lite-C, and try to go on with that, because, in fact, I had the total control over what was happening in the car... when something really happened tongue

By other side, I dont have too much time to spend on it.

Using Newton, I remember also that the simulation was something slow, and my physics runs very very fast, because it was only that.... racing car physics.. nothing else.

I already invested blood, sweat and tears a lot in this type of thing. And life goes on very fast also, much more then 3DGS.

Maybe we can exchange info in the near future when I get more advanced on it ?

Cya, thankyou a lot.
Posted By: 3run

Re: Car racing - Physics - 09/06/11 17:54

I'm working on proper car physics ATM, I'm trying to get proper movement like this:
UDK Car
I can recreate almost everything, but not the handling... It's really hard to get proper steering at least for me.
Posted By: HeelX

Re: Car racing - Physics - 09/06/11 18:10

I have worked on a -fun- kart racing sim years ago and wrote everything with C-Script and in the first place it is really the easier route to go. But even though it had simplified physics, I didn't got it right and had problems everywhere: on the one side I tried to make it more realistic, but on the other side I always had trouble with the car alignment on the floor and the behaviour in mid air (like driving over ramps). But if you things like "whirling on bananas" and bombs and such stuff, it could be tricky do do it well with a physics-driven vehicle setup, yes.

Well, I guess it all depends on the requirements you have and how you want your physics simulation in the end.

If you advanced, sure, call me, why not.

Here is already one best practice I can give you from what I learned from my PhysX coding sessions: when defining positions and hinge axis directions and so on, try to place bones in your model and access them via their names. This is much more convenient and customizable than defining offsets and such via skills, like in the current vehicle templates.

[EDIT]

@3run: I wonder if the turret is an attached physics object (reacting on vehicle momentum and crashes and so on) or if it is attached as a seperate model (or via bone animation?). If the former, I wonder how they translate the crosshair direction into runtime constraint-parameters?
Posted By: 3run

Re: Car racing - Physics - 09/06/11 18:48

I didn't try to make turret, just that simple steering behavior. I think turret isn't physical object, I think it's just attached passable model (or probably part of the model, which turning via bones).
Posted By: Carloos

Re: Car racing - Physics - 09/06/11 20:00

HeelX

In the case of this kart racing sim, tell me one thing...

How do you managed to get collision against, for example, fences, and other karts ? how did you get whit what you collided, the angle of the collision, and the reaction that the kart shoud have according to that situation ?

This was where I got stuck.
Posted By: ventilator

Re: Car racing - Physics - 09/06/11 21:52

you can combine the advantages of both. most racing games do it this way.

use a physics body for the car chassis. it will handle collisions nicely.

use ray casting for the wheels and do your own wheel physics. there is a famous formula for wheel physics but i forgot its name. laugh it should be easy to find with google though.

edit: http://en.wikipedia.org/wiki/Hans_B._Pacejka

(you can't simulate extremely fast spinning wheels with rigid bodies since the frequency of the simulation limits the possible rotational speed.)
Posted By: Carloos

Re: Car racing - Physics - 09/06/11 22:27

Ventilator !

So nice to "hear" something from you, I admire a lot your work.

if you say "use a physics body for the car chassis. it will handle collisions nicelly" I will ask you..

When I worked with newton, bodies physical controlled couldn´t be moved by, for example, c_move. I had to disable the physical entity, move it, then reenable the entity again to newton.

If I could only calculate the physics and let the engine ( PhyxS or even Newton ) manage the collisions, I think then I will have a chance.

One more thing... how would you analise PhysX compared to Newton nowadays ? I see you were working on a new Newton wrapper, is it already usable for vehicles ?

Thakyou a lot for your reply, and sorry if my questions look too noobish. ( in fact I think they really are )


Posted By: ventilator

Re: Car racing - Physics - 09/07/11 07:45

physx is mostly about marketing. it's not a better physics engine than newton or bullet.

you have to move the physics body with the forces that you calculate for your wheels.
Posted By: Carloos

Re: Car racing - Physics - 09/07/11 12:41

Originally Posted By: ventilator
physx is mostly about marketing. it's not a better physics engine than newton or bullet.

That´s what I´m thinking of it by now. Yesterday I managed to assemble a car on it, and it feels worst then my old kart game with the old Newton... i´m really scared.

Originally Posted By: ventilator

you have to move the physics body with the forces that you calculate for your wheels.

I understand, but its too vague. Is somewhere an example of how is it possible to do ?

Another thing that I noticed ( maybe it´s only me ) is that looks like the rotational "pivot" center of the car, is in the exact middle of the chassis. ( where my 0,0,0 is ) what makes the car turn horribly.

I will try to change this to the exct center of the rear axis, to see if it gets better.

Edit : Yes, it makes it looks much better...

Is already possible to use the latest newton in A8 to make a car ? And sorry for ask, but, wich one is the latest Newton wrapper download ? I readed some posts about it, but I´m too losted to get a clue of how it is by now.

Thankyou again.


Posted By: 3run

Re: Car racing - Physics - 09/07/11 17:16

About fake physics which you've made with 'c_move' dude, you should make adjusting tilt and roll to slopes a bit smoother.
Posted By: ventilator

Re: Car racing - Physics - 09/07/11 17:27

i don't know where you can download the latest newton wrapper. it didn't get done by me but someone else and i don't use gamestudio much at the moment...

there are examples for raycast cars for both, newton and bullet. not gamestudio specific examples but it should be possible to figure out how it works. you could also look into games like supertuxkart (it uses bullet).
Posted By: Carloos

Re: Car racing - Physics - 09/09/11 04:21

Hi all.

Ventilator : I found the wrapper, but when I tested the car sample, the car fall across the ground. Will check it to see how it works.

I´m really interested in the idea you gave, using physics to collisions and raycast and made the physics calculations by myself. If I can move the car only with code and use physics take care of all collisions, would be a dream coming true.

Using PhysX, I got how to assemble the car and make it move reasonably.

To help a lil bit, I placed a Panel to help set some physic aspects, and I´m thinkng in improve it with all the values needed :



I dont liked too much the behaviour, and it was a pain to set physics values to achieve something at least aceptable.

This is what I got by now :

Youtube video of my PhisX car

Cya.


Posted By: 3run

Re: Car racing - Physics - 09/09/11 13:15

It doesn't really looks realistic.
Posted By: HeelX

Re: Car racing - Physics - 09/09/11 14:19

From first person perspective it looks quiet cool. With the 3rd person camera you see that the car has not much grip wink
Posted By: Carloos

Re: Car racing - Physics - 09/09/11 15:20

Yeah, It doesnt looks realistic. And also, it doesnt have much grip.

I made a mistake in the track modelling. I tryed to make the center of the track a little higher then the part closer to the grass.

This is making the physics react strange.
When the car goes into the turns, and even in the straight part, It changes direction a lot.

Only for fun, I will model another track, completely flat from side to side, to see what happens.

I Think the next step will be what Ventilator said : c-lite for the movement, physics for the collisions.

If I could manage the speed, turns and skkiding with Lite-c and, the PhysX for the collisions, I would get something nice.

I have a nice car behaviour wrote in c-script that I can port to c-lite easily.

My dount is : I know that we cant c_move a physics active object. Apart of this, I think... when the car collide with something, or another car... what could happen ? How to manage it ? Any ideas ?

Questions, too much questions.
Posted By: Tobias

Re: Car racing - Physics - 09/10/11 11:16

Is your car the standard raycast car? If yes you can adjust the grip on the track with car_frictionLatF and car_frictionLatR. The default values are a little too small when the car is heavy.
Posted By: 3run

Re: Car racing - Physics - 09/10/11 11:37

I.ve faced problem with turning on flat levels too, they were made out of level blocks. I've seen that problem with another car examples which aren't made by me. May be that some kind of physX bug in game studio? Knights on wheels from samples folder has that problem as well...
Posted By: Carloos

Re: Car racing - Physics - 09/10/11 16:05

Hi Tobias.

It Looks like this. I will check it later. Now I´m finishing a new track, better modelled, to work in the physics part without worry about imperfections in the asphalt.

Thanx for your tip.
Posted By: Carloos

Re: Car racing - Physics - 09/16/11 02:33

This is being very difficult to understand / implement.

I´m using this code I found somewhere in the forums, and changed a few things to my convenience, but nothing that could break its functionallity :

______________________________________________________________

function simple_car()
{
vecGravity.x = 0;
vecGravity.y = 0;
vecGravity.z = -9.81;

pX_setgravity (vecGravity);

ENTITY* car = ent_create("F3.mdl",vector(6700,25500,5),NULL);

pXent_settype(car,PH_RIGID,PH_CONVEX);
pXent_setmass(car,1);

car.material = mtl_envmirror;
car.shadow = ON;

pXent_setmassoffset(car,vector(NULL,NULL,-3),vector(1,0.1,1)); //moves the center of mass 10 quants down.

ENTITY* BLwheel = ent_create("tyre.mdl",vector(car.x - 60,car.y - 20,car.z + 8 ),mass);
ENTITY* BRwheel = ent_create("tyre.mdl",vector(car.x - 60,car.y + 20,car.z + 8),mass);
ENTITY* FLwheel = ent_create("tyre.mdl",vector(car.x + 46 ,car.y - 25,car.z + 8),mass);
ENTITY* FRwheel = ent_create("tyre.mdl",vector(car.x + 46,car.y + 25,car.z + 8),mass);

pXcon_add ( PH_WHEEL, FLwheel, car, 0 );
pXcon_add ( PH_WHEEL, FRwheel, car, 0 );
pXcon_add ( PH_WHEEL, BLwheel, car, 0 );
pXcon_add ( PH_WHEEL, BRwheel, car, 0 );

pXcon_setparams2(BRwheel, NULL,vecBRwheel, vecBRwheel2);
pXcon_setparams2(BLwheel, NULL,vecBLwheel, vecBLwheel2);
pXcon_setparams2(FRwheel, NULL,vecFRwheel, vecFRwheel2);
pXcon_setparams2(FLwheel, NULL,vecFLwheel, vecFLwheel2);

while(1)
{

if(key_a)
{
speed += (1 * time_step);
}
else
{
if ( speed > 0
{
speed -= (1 * time_step);
}
}

if(key_z)
{
speed -= (1 * time_step);
}

if(key_n)
{
tyreAngle -= ( 2 * time_step) ;
}
else
{
if (tyreAngle < 0)
{
tyreAngle += ( 1 * time_step) ;
}
}


if(key_m)
{
tyreAngle +=( 2 * time_step);
}
else
{
if (tyreAngle > 0)
{
tyreAngle -= ( 1 * time_step) ;
}
}


pXcon_setwheel (FLwheel,tyreAngle,0,0);
pXcon_setwheel (FRwheel,tyreAngle,0,0); // steer to the right
//pXcon_setwheel (BLwheel,0,speed,0);
//pXcon_setwheel (BRwheel,0,speed,0);

var max_speed = 300;
var ang_force = speed * 100;

//pXcon_setmotor(car,vector(-ang_force, max_speed, 0), nullvector);
//pXcon_setmotor(car,vector(-ang_force, max_speed, 0), nullvector);

pXent_addvelcentral(car,vector(((speed) * time_step),0,0));
pXent_addvelcentral(car,vector(0,0,-10));

pXent_addvelcentral(FLwheel,vector(0,0,-50));
pXent_addvelcentral(FRwheel,vector(0,0,-50));
pXent_addvelcentral(BLwheel,vector((speed),0,0));
pXent_addvelcentral(BRwheel,vector((speed),0,0));

var temp[1];
var camTilt;
var camPan;
var cam_dist=0;
var CamFromWheel = 10;
var CamFromGround = 5;
var x_cam;

camera.arc = 72;
camera.clip_near = 0;
camera.clip_far = 100000;
camTilt = car.tilt ;
camPan = car.pan - 180 ;
cam_dist = clamp(0,CamFromWheel,20);
camera.x = ((((car.x))+ cos(camPan)*(cam_dist*cos(camTilt)))) + x_cam ;
camera.y = ((car.y + sin(camPan)*((cam_dist*cos(camTilt)))));
camera.z = car.z + 20 ;
vec_set(temp,car.x);
vec_sub(temp,camera.x);
vec_to_angle(camera.pan,temp);
camera.tilt = -3;
wait(1);
}
}


______________________________________________________________

but... an interesting thing is happening :

When the car is pointint to positive x vector, and I´m pressing the "a" key, it accelerates ok. then I turn 180 degrees in the track, and the orientation of the car is the opposite.

Then the car slows very fast, and it start to go in reverse !

It´s very disappointing, I know I´m very nooby in the PhisX thing, maybe also in coding, but this is so... weird...

Ipm really interested in learning and maybe applying what Ventilator said, but, if I can´t even manage to understand well this code above...

Well, any help or tips will be HIGHLY appreciated.

Cya
Posted By: painkiller

Re: Car racing - Physics - 09/16/11 10:21

take a look at my PhysX car script in Aum 101
Posted By: Carloos

Re: Car racing - Physics - 09/16/11 12:02

Thankyou, Painkiller.

I will check it tonight.
Posted By: Carloos

Re: Car racing - Physics - 09/16/11 12:13

Is it in the download part of the AUM 101 ?
Posted By: 3dgs_snake

Re: Car racing - Physics - 09/16/11 12:46

Yes, here aum101code\hot_forum\Painkiller - 2nd\PhysX_car_code
Posted By: Carloos

Re: Car racing - Physics - 09/16/11 12:51

Thankyou, downloading.
Posted By: 3run

Re: Car racing - Physics - 09/16/11 15:47

Carloos, PM me please.
© 2024 lite-C Forums