Top Down Car Physics

S

sprotz

Guest
Does anyone know any FREE tutorials or examples on how to implement top down car physics with spinout for gamemaker ? I'm surprsed that there aren't any, given the box2d physcs engine inbuilt in gamemaker studio. I wanted to develop a game involving cars but I'm stuck for now.
 

rIKmAN

Member
I'm surprsed that there aren't any, given the box2d physcs engine inbuilt in gamemaker studio.
There are, you can find them by using this magical thing called Google which searches the internet.

This looks like a good tutorial series - found by typing "gamemaker top down car physics" into Google.

 
S

sprotz

Guest
I see, but that isn't real enough. The car turns while stationary, and the sideways slipping is too extreme. The previous game maker 8 had excellent examples, I remember it involved adding hinge joints, rail joints and motor force to them.
 

rIKmAN

Member
I see, but that isn't real enough. The car turns while stationary, and the sideways slipping is too extreme. The previous game maker 8 had excellent examples, I remember it involved adding hinge joints, rail joints and motor force to them.
You didn't specify any of that in your first post, you said you couldn't find any.

Why can't you use the GM8 one you mention and adapt it to GMS as a learning project?
 
S

sprotz

Guest
I did but most of them use DLLs, I wanted to develop for the HTML5 target platform which doesn't support DLLs. So I needed an example in pure Box2d engine, or non-DLL extensions. Meanwhiile I'm going to try to translate my GM8 project which uses GMPhysics into game maker studio's Box2d, until someone here helps me find any examples.
 

Genetix

Member
I learned most of the GMS physics from a youtube channel called realtuts or something like that, but ultimately just had to look through the manual and do quite a bit of experimenting to get it all figured out. It's worth just playing around with on your own - I eventually was able to build some pretty cool things like a Motorbike game and a Skateboarding game with functional wheels and more. I'm pretty sure you can find videos on all of the specific mechanics you want - not sure anyone will have built exactly what your looking for though, it's best to watch that stuff and learn from it rather then just try to grab it and apply it to a project.
 

Genetix

Member
Thanks @sprotz I need to work on my spelling/grammar as it is, especially when it comes to coding which leads to problems. You do get nit-picker award of the day though haha!

That being said - sometimes (especially when I'm at work) I write down stuff here pretty fast and don't have time to proof-read it. Hopefully you can look past the syntax of the message and extract some value from it's meaning.
 
N

Never Mind

Guest
This may help someone.
---------------------------------------------------------------------
///scr_kill_lateral_velocity()
var goodspeed = point_distance(0,0, lengthdir_x(phy_speed, image_angle) , lengthdir_y(phy_speed, image_angle)); //edited here to use phy_speed instead of phy_speed_x/y
phy_speed_x = lengthdir_x(goodspeed, image_angle) ;
phy_speed_y = lengthdir_y(goodspeed, image_angle) ;
---------------------------------------------------------------------
It would probably be better to apply a cancelling impulse, rather than setting phy_speed_x/y directly..
I realize this is not what's being asked for here.

I wrote it after reading through this tutorial:
http://www.iforce2d.net/b2dtut/top-down-car
 
Last edited by a moderator:

Yal

🐧 *penguin noises*
GMC Elder
I see, but that isn't real enough. The car turns while stationary, and the sideways slipping is too extreme. The previous game maker 8 had excellent examples, I remember it involved adding hinge joints, rail joints and motor force to them.
The built-in physics system still has several types of joints, so you should be able to apply the thinking behind the original system to the new engine even without an copypasteable example.
 

Jezla

Member
I know you said free, but I've done a little tinkering with this asset, and found it would be a good base to build on. It's essentially a GML build of the Box2D tutorial @Never Mind linked above.

I found that it could be improved to be made more versatile and realistic, even to where you could implement variable grip levels to mimic different driving surfaces or car setups. It's worth the $2, in my opinion.
 
S

sprotz

Guest
This may help someone.
---------------------------------------------------------------------
///scr_kill_lateral_velocity()
var goodspeed = point_distance(0,0, lengthdir_x(phy_speed_x, image_angle) , lengthdir_y(phy_speed_y, image_angle));
phy_speed_x = lengthdir_x(goodspeed, image_angle) ;
phy_speed_y = lengthdir_y(goodspeed, image_angle) ;
---------------------------------------------------------------------
So how do I use this code? Should I just put it in the step event of the car and apply a force for acceleration ?
 
N

Never Mind

Guest
I usually just give things a try and see what happens.
However, it has a specific purpose within the context of how that tutorial sets things up. I suggest skimming through it (even though it's a c++ tutorial) if you want to understand when / why it's useful.

My suggestion for you sprotz
Would be either purchasing the asset
Jezla linked to, or to start going through the Drift Racing Tutorial rIKmAN posted. You can then modify either to your liking.

If you're not looking to tailor something yourself, then I guess you stuck with the asset.
Perhaps someone will eventually make another tutorial.
 
Last edited by a moderator:
S

sprotz

Guest
I will experiment and tweak the drift example I have. I have just one question. When I attach the four wheels to the car body and set friction etc. for each wheel, should I set friction to the car body as well as damping lateral velocity similar to the wheels? or should I leave the body frictionless? And where do I apply force for acceleration? To the front wheels or to the body ?
 
N

Never Mind

Guest
Most cars are front wheel drive since it's a tad easier to control and saves cabin space and weight.
When I attempted my own top down Box2D car last time, I left the body with no damping, no linear friction, and no angular damping..
I also think I was testing around with giving the wheels no friction, some linear damping, and small amount of angular damping.
It would probably be realistic to use friction for terrain differences, if you can somehow make it so the whole car passes through larger objects that represent different ground materials.. I haven't thought about how that might work though.

If I have time I'll look for the project file, but I don't think I got it to very satisfying level anyways. I started working on something else.
 
S

sprotz

Guest
I am working on my car physics, so far it keeps sliding around, so how do I kill lateral velocity and apply sideways friction ?
 
N

Never Mind

Guest
The code I posted earlier was a script called scr_kill_lateral_velocity .. did you notice that?
Directly setting phy_speed_x/y may not be the best way to accomplish the task though. Please explain further if I'm not understanding.

To allow some slipping / drifting you would just not kill it all the way. You could use lerp() to interpolate the x/y speed somewhere between the original values and the new killed values.
 
Last edited by a moderator:
N

Never Mind

Guest
Yeah I know it's a selfish threat.. I guess I have a personal agenda beyond just trying to help people. Sorry everyone!
I edited it out.
I know likes are meaningless it's just a personal goal to get more, and it helps me feel like I'm not wasting my time.

EDIT: Yeah, sorry again I was acting stupid earlier.

I dug up that project file and fixed it up a bit. Here's an example and download:

Zipped project file:
https://drive.google.com/file/d/0B9sznQG39De2SFhWTUZpS3dMdnc/view?usp=sharing&authuser=1

It's definitely not the best! I did not enable any drifting.
 
Last edited by a moderator:
S

sprotz

Guest
This is a good example. All that is left now is to enable drift and spinout, maybe by decreasng traction in the rear tyres accordingly.
 
N

Never Mind

Guest
Thanks! Feel free to use the car sprite or anything else.
It didn't take long to make.
 
S

sprotz

Guest
Finally made it ! I applied spinout to the physics. The spinout might be a bit too much though.
https://www.4shared.com/file/J0TeOseOei/top_down_car2.html

To control the amount of spin-out, simply change the sideways_friction variable in the kill lateral velocity script for the rear tyres. A slightly higher value than for the front tyres will result in a more stable car.
 
Last edited by a moderator:
N

Never Mind

Guest
I'd check it out but I don't really want to sign up to 4shared.com.. It wants me to sign up, or use a social media account.
I have enough random accounts on sites I don't use.
 

GMWolf

aka fel666
Here is a video tutorial series a made on building top down car physics with Box2D in gamemaker studio 1.x

Link to 1rst vid

Its a little old but the concepts are all solid. There is a slight error with the velocity conversion but the effect still works -> I think I forgot to convert from pixels to meters, and instead use high friction coefs.

I had a very realistic example laying around with weight distribution etc, but I lost the file when I reset my PC.
 
Top