Jump to content
  • Advertisement
Sign in to follow this  
Drilian

Help creating arcade racing simulator

This topic is 4863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, so despite my best efforts, I seem completely incapable of coding a simple driving simulation. It doesn't have to be super physically accurate, but it has to feel correct. I've read the Physics of Racing articles (which are, sadly, slightly over my head...way too detailed for what I want). The trick is, the track has loops and whatnot. The cars stick to the track (magnetics or whatever). Though I could probably extend a simulation to be able to handle that, if I could only get a flat-ground driving simulation running that doesn't blow. All I want is: 1. High-speed turn skidding to work mostly correctly 2. Ability to modify the friction of the road. 3. Wheels need to animate correctly (i.e. if the tires are slipping, they should animate slipping...if they're not, they should turn along with the road. 4. Slipping due to high acceleration (especially on ice and the like)...and brake locking. This may not sound hard to some of you, but I apparently really suck at physics programming. Can anyone give me some pointers?

Share this post


Link to post
Share on other sites
Advertisement
Sad, but there is no way of doing physic simulations -- undetailed.
There's one good article (not too complicated):

http://home.planet.nl/~monstrous/tutcar.html

Btw it's the only normal tutorial of car physics for games on the net.

But if you don't want waste your time reading all the info, for simple
car physics you can use ODE, Newton, Tokamak phys. engines.

Share this post


Link to post
Share on other sites
If you're not really good at physics, then it will be very hard to implement such detailed features. Try to isolate one problem, and solving it, in stead of trying to fix them all together at once.
Write the problems down, draw them on a paper, get the big picture, and if it's just too hard, search for a skilled person who can teach it to you, or consider using a pre-made engine like in the post above.

Whatever you do, don't get frustrated if you can't solve the problems. Just take time and decide what's best for you.

Share this post


Link to post
Share on other sites
Quote:
All I want is:

1. High-speed turn skidding to work mostly correctly
2. Ability to modify the friction of the road.
3. Wheels need to animate correctly (i.e. if the tires are slipping, they should animate slipping...if they're not, they should turn along with the road.
4. Slipping due to high acceleration (especially on ice and the like)...and brake locking.

This may not sound hard to some of you, but I apparently really suck at physics programming.

1)This is the difficult one...
2)Whenever you do friction introduce a constant to the equation, found from whatever material the wheel is touching (I can't be any more specific without knowing how you store your level).
3)Store the rotation angle of the wheel. It starts at zero, every time you update the wheel then just do: wheelAngle += spinRate * timestep. Then you need to build a rotation matrix taking this rotation and also the rotation turning the wheels for steering if applicable. Simply render the wheel with this matrix (assuming your whel is a 3D model?)
4)This is very closely related to 1), the accelerating part anyway. The brakes are slightly easier. You just want to apply a torque to the spinning wheel, or you could fudge this (to lock the wheels just set wheel.SpinRate = 0!).

I don't know where you stand with basic physics/mechanics though - do you understand force, torque, inertia, friction etc? That's all you really need - you can email me if you want as I just recently got to a nearly complete wheel/tyre/engine model which I'd be happy to discuss/explain...

Share this post


Link to post
Share on other sites
don't read any car physics papers (espicially the one posted above) if you are trying to create an arcade racing game. when it comes to car simulation, you can go one of two ways-

make a realistic car racing simulator based off of real physics, extremely complicated equations, many many magic constants, long long pages of source code that you will either have memorized or wont understand at all by the end of the project--or both, etc,

--or--

you can use your knowledge of competing differential equations to model car behavior based on extremely simplified equations that dont take long to execute, are easy to read and understand.


at the end of the day, if you go the physics model (which I tried, got close to completing, and failed at doing, even though I completed my physics series, read *books* <-- plural, on car physics, had a mechanic friend help me out, read pdf's on automated car handling/control in situations where drivers loose control, etc) but who knows, you may be able to do it, or you can use the other method.

another thing you will want to consider is that a 'fun' car racing game does not necessarly = a realistic racing game. the physics model I had for my game was working perfectly, but it was boring as hell to play and annoyed the hell out of me. so I continued to tweek with values, add it artificial equations where they shouldn't be, mixed in some functions in a futile attempt to make the simulation 'fun'.


before coding, i spent months modeling equations on paper first. even then, after that project (about five months of work) i was pretty drawn out and tired of coding. often in my past, i start projects but after so many months of trying to get something done without results, i just cant take it anymore and it makes me hate myself as well as programming. when we think about it--a car simulator. that shouldn't be hard, right? you waste a lot of time making a sexy car model, creating your level editor, adding collision detection (floor and wall collision detection have to be handled seperately, spring model for a chase cam [car chase cams are even HARDER to do than fps chase cams because of that 'drifting' and its even easier to make your players motion sick]), etc., so if you are gonna try and make a car sim, make sure you know what you are getting into and plan out your steps. if I could go back in the past, i would have used the second technique (diff eq) right off the bat and perhaps I would have a racing game sim today.

though many people do not talk about it, i think others have failed the same way I have because you do not see a lot of indie programmers releasing car racing games.

anyhow, all that said, my advice to you is as follows:

0. (edit) I don't know if you are trying to make a 3d car sim or not but if you are, make sure you start in 2d. you won't want to move up to 3d for a loooooooooong time (aka not until youve done a shitload of testing and all the models are working the way they are supposed to).

1. start with your standard 'tank' physics model where your vehicle grips the ground 100% of the time. you will probably accomplish this by using some equations that relate angular velocity to the wheel angle using the wheelbase.

2. create an 'ice' physics model. imagine having a block of, err, a block on ice. you can only move the block in one direction and stir the block. this will be your alternate extreme.

3. crete some values (at least three or four) that you will use to average/compete these two models. maybe one based on the vehicles speed, maybe one based on the slip ratio of the front tires to the rear tires, maybe one based on the angle between the cars velocity vector and direction vector, and maybe one based on some other easily controllable value like say the magnitude of the handbrake.

you will, of course, have to mess with these values until you get a model that feels right, but it will produce MUCH better results, run FASTER, and be a WHOLE lot easier to program than trying to come up with equations to model a car. and remember, realistic !~= fun.


good luck to you and I hope you are accomplish what I was not.


----
Edit:

here are the screenshots of the last build of my car project before i scrapped it:

01
02

----

if, for whatever reason, you do decide to go the physics route, then this is perhaps the most useful piece of information you will find on the internet which will assist you.

Share this post


Link to post
Share on other sites
Thanks for the help so far, everyone.

I don't need a realistic physics model. Not by a long-shot.

d000hg helped me a bit via email, so I have a good start.

The physics will be effectively 2D. That is, the car won't ever leave the track. They're stuck :)

I think I have enough to go on for now, thanks to you people :) I appreciate the answers!

Thank you!

Share this post


Link to post
Share on other sites
Quote:
Original post by Uthman
...
Interesting point - for some racing games you can doubtless use much less realism. I guess not many amateur/indie developers get racing games finished but there sure seem to be a lot of them worked on! Although there are a few good ones I've seen. Your screenshots did make it look pretty far along - what exactly was it that finally 'broke' your project?

I don't think the handling should be a reason not to use physics though. Real cars can do pretty cool stuff...

Share this post


Link to post
Share on other sites
i programmed a vector map editor that felt a lot like the old way we used to setup bsps. it was actually pretty cool, you could select different track 'tiles' making tracks was as easy as drawing lines. i finally broke because of two things:

no.1 i got sick and tired of spending weeks tinkering with parameters without ever acquiring the effect i sought after.

no.2 by the time i got to that point, the engine had some backing in real physics but a lot of other junk just thrown in to try and make it feel better. though the code was clean and easy to understand, there was just too much garbage going on.


i hope to eventually restart the project someday when my school and work load have lessened.

Share this post


Link to post
Share on other sites
What if you kept track of two vectors. One the current direction of the car and Two the steering direction of the car. If there is really good friction on the road make the car follow the sterring vector more and the less friction make the car follow the current vector more. In other words you could make friction a decimal number and multiply it by the difference in the current vector and desired vector and add that to the current vector.

Share this post


Link to post
Share on other sites
its not that the editor didnt work, its just that i hate programming game editing tools =p that and the project itself was moving at a salted snails pace

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!