Car simulation using physics engine (PRO)

Posted By: Rocko75

Car simulation using physics engine (PRO) - 02/20/04 19:36

Hello,

i'm looking for a usefull example, how to generate a car using the physics engine. I found the code from Ventilator, but without the used level I don't really get started.

Someone knows a good tutorial, or where to find a complete level to take a look at?

Thanx,

Arnim.
Posted By: Salva

Re: Car simulation using physics engine (PRO) - 02/20/04 21:12

If You want to use the NewtonGameDynamics, there is a very good Car levels
and the tutorial as well.



Bye

Salva
Posted By: Rocko75

Re: Car simulation using physics engine (PRO) - 02/20/04 21:17

Quote:

If You want to use the NewtonGameDynamics, there is a very good Car levels and the tutorial as well.




I know about this engine, but I have to use the Game Studio engine.

Or is the Newton engine the better one?

Arnim.
Posted By: Salva

Re: Car simulation using physics engine (PRO) - 02/20/04 21:32

NewtonGameDynamics is a plugin for 3dGS about 30MB,
You could download them at:

www.physicsengine.com
Greetz
Salva
Posted By: fastlane69

Re: Car simulation using physics engine (PRO) - 02/21/04 04:47

Boys, a bit of advice.

The forums are RICH with discussions on this and other topics.

Go to SEARCH and do a 1 year search on car physics....plan to be busy for a few hours reading what other people have said!!!

This strategy is true in general; before you post a question (and I'm not flaming you, just advice )do as extensive a search on the forums as you can. If still no answer, then post away!!

Enjoy and keep us posted on your projects!!!

Posted By: Newton

Re: Car simulation using physics engine (PRO) - 02/21/04 07:05

Actually there is very little in the furum about cars, there are however two working solutions(solutions being the key word here) provided with the plug-in, for some type of vehicles.
I said also that I will release a working sample or a car this weekend.
the demo will be simple and it will allow for some good arcade car simulation.

In the Newton furum we just focus in providing practical answers to simple question. We just do what we can with the tools that we have.

We try to stay away of the Quatum Cosmogical effect like this post by Fastlene69 seems to subjects

Quote:


Finally, to get a bit esoteric, there is mounting evidence that while Newtons Grav law works well at our distance scales, on the scale of the Quantum or the Cosmic, then it **seems** that the traditional f= (Gm1m2)/(r*r) actually fails; new facts ursurping old laws!



!

We also try to simplify the problems rather than to make then gratuitosly complex. like this other post also by fastlaner69 subject with plenty of rhetoric, but them dismisses the problem altogether.
like this other post.

Quote:


Hate to burst your bubble but making a spherical world will be challenging even without messing with these levels of maths. If the above doesn't make sense to you, you may be a bit over your head as regards a spherical environment.

Long story short, there is no quick and easy way to do this in 3DGS that I'm aware of. It can be done I think, but would require alot of coordiante transformation work and thus if you aren't comfortable with sperical, polar, and cartesian coordinate, then my advice is to "fake" the spherical world as has been suggested.





BTW. the working car script is up and working. it has not been posted because we are working tryng to fix a serius bug on the Plug-in. (yes we admit our bugs)
So if you are patient you will have the demo this weekeng.

Thank
Newton



Posted By: fastlane69

Re: Car simulation using physics engine (PRO) - 02/21/04 14:51

While there are no tutorials on car physics in 3dgs that I know of, I do know for a fact that since the introduction of the 3DGS PE, there has been a wealth of car physics discussions. Furthermore, I would bet that pre-PE there were discussions and likely some demos of car physics.


(PS: I stand by my opinion that modeling gravity for a spherical level is challenging and difficult in 3DGS...but this has nothing to do with this post so why even bring it up? Are you just peeved that Einstein ursurped Newton in that thread? )
Posted By: Newton

Re: Car simulation using physics engine (PRO) - 02/23/04 08:06

As promised last time I posted here. You can download the vehicle demo at: arcadeCar

The vehicle model is by no mean realistic, but it is good enough for an arcade type of game. For more Realistic vehicle model we have to wait for version 2.0 of Newton.

All the art and the majority of the script code was provided by Ventilator, I modified the script to make it works with Patch 1.5

Cars are all wheel drive, and there is no transition, gears, or sound effects.
You can add those effects by adding script code to any of these three function in the file vehicle_playground.wdl

function VehicleBeginEvent(vehicleConst)
function VehicleEndEvent(vehicleConst)
function VehicleTireEvent(vehicleConst, tyreIndex)

it should be easy simple enought to add for example sound effects.

Newton

Posted By: Xenolith

Re: Car simulation using physics engine (PRO) - 02/23/04 19:56

Thank You!! OMG!! :D:D

I only have one problem, my wheels are on a right angle to the car
This is what it looks like: www.zer0-x.ampedgamers.com/images/wtf.jpg
Posted By: ventilator

Re: Car simulation using physics engine (PRO) - 02/23/04 20:07

you could try to rotate the chassis by 90° in wed.
Posted By: Xenolith

Re: Car simulation using physics engine (PRO) - 02/23/04 20:21

I've tried tonnes of rotating. wheels, chassis and all
Posted By: Newton

Re: Car simulation using physics engine (PRO) - 02/23/04 23:28

you need to set the vehicle just like it is in the demo.

load the chassis in the model editor, and rotate the verices until the principal
axis are aligned the same way that the model in the demo.

do the same for the tires.

the go to the level editor and reposition the car.

before you do this first make a backup of you models.
Newton.
Posted By: Xenolith

Re: Car simulation using physics engine (PRO) - 02/24/04 16:03

Thanx alot man! i was trying 2 fix that for hours

Just one more thing, is there a way to make the camera follow the car rather
than having to constantly rotate it with right click?
Posted By: ventilator

Re: Car simulation using physics engine (PRO) - 02/24/04 16:48

Quote:

Just one more thing, is there a way to make the camera follow the car rather
than having to constantly rotate it with right click?


sure, just look for the camera movement function and change it! ...probably there are several threads about such camera scripts on the forum...
Posted By: Don Pedro

Re: Car simulation using physics engine (PRO) - 02/25/04 00:21

Here is one piece of code that will do it (from Georges magicbox)

camera.x = p_vehicle.x - 350 * cos(p_vehicle.pan);
camera.y = p_vehicle.y - 350 * sin(p_vehicle.pan);
camera.z = p_vehicle.z + 100;
camera.pan = p_vehicle.pan;
camera.tilt = -10;

btw. comment all other code in while loop...
Posted By: Newton

Re: Car simulation using physics engine (PRO) - 02/25/04 02:38

that is a nice camera follow code. but is too rigid, you can add some nice dampening by filtering the camare angle a litle.
somethihg like this:
Code:

var prevPan = 0;
function SetCamera()
{
var tau;
camera.x = p_vehicle.x - 350 * cos(p_vehicle.pan);
camera.y = p_vehicle.y - 350 * sin(p_vehicle.pan);
camera.z = p_vehicle.z + 100;
//camera.pan = p_vehicle.pan;
// apply a low pass filter to the camera angles
// tau = 0.3; // play with this for different damping effects
prevPan = prevPan * (1 - tau) + p_vehicle.pan * tau;
camera.pan = prevPan;

// to do: apply fi;terring to this angle too
camera.tilt = -10;
}



this code will produce a nice lagging of the camara allowing you to see the relative movement of the vehicle chassis.

I hope it works because I did not tested.
(Please do not take it offesinvely, I just one to help you people )

Newton

Posted By: Don Pedro

Re: Car simulation using physics engine (PRO) - 02/25/04 03:20

Yup!

It's far from perfect especially if the car is going fast and flies off from a bump. During flight the camera goes like a wild horse

I tested the code you gave Newton. There's on thing though. On a certain angle it "jitters" so there should be some kind of a IF statement or something to prevent that to happen. I have no idea (yet) how to use the debugging tools so I don't know variable values on that certain state but it's not >360 degrees anyway - that I've tested
Posted By: Newton

Re: Car simulation using physics engine (PRO) - 02/25/04 03:29

did you uncomment the line where tau is set to 0.3?
I added a comment there by accident.
you can also make tau smaller.

yes you are correct. the interpolation suffer for angle aliasing.
that is when one angle is on one side of the axis and the previus is on the other side. for example one angle is 1 degree and the other is 359. The difference should be 2 degrees, but it come out to be 361. You can use the mod function.
It may be difficult to get it work correctly.
if it does not work. I will post a camera interpolation function tonight.
all written with script code.

Newton.



Newton
Posted By: Newton

Re: Car simulation using physics engine (PRO) - 02/25/04 14:37

@ don pedro
I tested you original camera function. I found it very nice the way it was first proposed.
there is not need to do anything to it. In fact what I proposed is totally incorrect.

this is the function I tested
Code:
  
starter move_camera()
{
camera.arc=72;
camera.clip_near=20;
camera.clip_far=24000;

var cam_ang[3];
var cam_dist=500;
cam_ang.pan=180;
cam_ang.tilt=30;
cam_ang.roll=0;
while(!p_vehicle){wait(1);}

while(1)
{
camera.x = p_vehicle.x - 350 * cos(p_vehicle.pan);
camera.y = p_vehicle.y - 350 * sin(p_vehicle.pan);
camera.z = p_vehicle.z + 100;
camera.pan = p_vehicle.pan;
camera.tilt = -10;
wait(1);
}
}



Newton


Posted By: vrkaya

Re: Car simulation using physics engine (PRO) - 02/26/04 04:20

Hi everyone,

I added an enhancement to the new camera code so you can change your viewpoint in relation to the car. I didn't like always being directly behind it. Just change the function to this, then use the "left arrow" and "right arrow" to adjust your view angle of the car. We need to also add a function to reset the car. I keep flipping it on it's top

Code:

starter move_camera()
{
camera.arc=72;
camera.clip_near=20;
camera.clip_far=24000;
var cam_ang[3];
var cam_dist=500;
var pan_adjustment = 0;
cam_ang.pan=180;
cam_ang.tilt=30;
cam_ang.roll=0;

while(!p_vehicle){wait(1);}

while(1)
{
camera.x = p_vehicle.x - 350 * cos(p_vehicle.pan + pan_adjustment);
camera.y = p_vehicle.y - 350 * sin(p_vehicle.pan + pan_adjustment);
camera.z = p_vehicle.z + 100;
camera.pan = p_vehicle.pan + pan_adjustment;
camera.tilt = -10;

// Adjust viewing angle with left arrow and right arrow keys
if (key_cul == 1)
{ pan_adjustment += 1; }
if (key_cur == 1)
{ pan_adjustment -= 1; }

wait(1);
}
}



Regards, Ron
Posted By: vrkaya

Re: Car simulation using physics engine (PRO) - 02/26/04 04:27

Oops, I didn't notice that the left arrow was rotating right and the right arrow was rotating left. Duh.

I made a small change to correct that.

Code:

starter move_camera()
{
camera.arc=72;
camera.clip_near=20;
camera.clip_far=24000;
var cam_ang[3];
var cam_dist=500;
var pan_adjustment = 0;
cam_ang.pan=180;
cam_ang.tilt=30;
cam_ang.roll=0;

while(!p_vehicle){wait(1);}

while(1)
{
camera.x = p_vehicle.x - 350 * cos(p_vehicle.pan + pan_adjustment);
camera.y = p_vehicle.y - 350 * sin(p_vehicle.pan + pan_adjustment);
camera.z = p_vehicle.z + 100;
camera.pan = p_vehicle.pan + pan_adjustment;
camera.tilt = -10;

// Adjust viewing angle with left arrow and right arrow keys
if (key_cul == 1)
{ pan_adjustment -= 1; }
if (key_cur == 1)
{ pan_adjustment += 1; }

wait(1);
}
}



Regards, Ron
Posted By: vrkaya

Re: Car simulation using physics engine (PRO) - 02/28/04 13:03

I have added more realistic acceleration to the car, and have added "brakes" with the following code. To use the brakes, just tap the 'x' key while the car is moving and it will feel like you are tapping the brakes - to slam the brakes on, just hold down the 'x' key and watch the car skid to a stop. Replace the NewtonVehicle action in your vehicle_playground.wdl file with this:

Code:

action NewtonVehicle
{
var car;
var forward_flag;
var reverse_flag;
var engine_torque;

// save the pointer to the entity as the player
p_vehicle = my;

// create the vehicle
NewtonCreateVehicle (wood_material, VehicleTireEvent, VehicleBeginEvent, VehicleEndEvent);

dll_handle = newtonHandle;
car = NewtonGetBody (my);

// make the car always active
NewtonSetBodyAutoActiveState (car, 0);
NewtonSetBodyActiveState (car, 1);

// asign a special force event to the rover
NewtonSetBodyForceAndTorque (car, VehicleForceEvent);

my.carSteerTorque = 0.0;
my.carEngineTorque = 0.0;
forward_flag = 0.0;
reverse_flag = 0.0;

// this is the vehicle control loop;
while (1) {

// read wheel controls
if(key_a)
{
my.carSteerTorque += .15 * time; // smoothly turn wheels left
if(my.carSteerTorque > 1.0) // clamp
{ my.carSteerTorque = 1.0; }
}
if(key_d)
{
my.carSteerTorque -= .15 * time; // smoothly turn wheels right
if(my.carSteerTorque < -1.0) // clamp
{ my.carSteerTorque = -1.0; }
}
if(key_w)
{
if(forward_flag == 1.0)
{ engine_torque = 0.0;
forward_flag = 0.0;
}
reverse_flag = 1.0;

engine_torque += 10.0 * time;
if(engine_torque >= my.car_maxToque)
{ engine_torque = my.car_maxToque; }
my.carEngineTorque = engine_torque;
my.car_topSpeed = engine_torque * 4;
}
if(key_s)
{
if(reverse_flag == 1.0)
{ engine_torque = 0.0;
reverse_flag = 0.0;
}
forward_flag = 1.0;

engine_torque += 10.0 * time;
if(engine_torque >= my.car_maxToque) // clamp
{ engine_torque = my.car_maxToque; }
my.carEngineTorque = -engine_torque; // transfer calculation
my.car_topSpeed = engine_torque * 4; // Calc topSpeed based on torque level
}
if(key_x) // Apply brakes
{ engine_torque -= 10.0 * time;
if(engine_torque <= 0.0)
{ engine_torque = 0.0; }

if(forward_flag == 0.0) // Car is moving forward
{ my.carEngineTorque = engine_torque; }
if(reverse_flag == 0.0) // Car is moving in reverse
{ my.carEngineTorque = -engine_torque; }
}

// Return turned wheels to straight
if(my.carSteerTorque > 0.0)
{ my.carSteerTorque -= .05 * time; }
if(my.carSteerTorque < 0.0)
{ my.carSteerTorque += .05 * time; }

wait(1);
}
}



Regards, Ron
Posted By: steve52

Re: Car simulation using physics engine (PRO) - 05/24/04 21:57

I'm still working on the with carlevel but the car seems to skid to much (like it's driving on a wet surface.

I've tried to work with a own fix but i don't seem to get it to work.
Anyone else had more luck ?


Tnx in advance,

steve
© 2024 lite-C Forums