Creating a 2D Car?

Official forum for the Chipmunk2D Physics Library.

Creating a 2D Car?

Postby Aya » Mon Nov 01, 2010 9:52 am

Hi,

I am very new to Chipmunk Physics and am wondering if it's possible to create some Car-Physics for a 2D Racing Game..?
And is drifting possible, or is it built in since it's real physics etc..? :)

If it's possible, could anyone could give me a hint on how I set it up? Which constraints do I need?

Thanks,
Aya
Aya
 
Posts: 3
Joined: Mon Nov 01, 2010 9:48 am

Re: Creating a 2D Car?

Postby slembcke » Mon Nov 01, 2010 10:29 am

Unfortunately, it's not quite that simple. Chipmunk isn't really designed with top down 2D physics in mind. The Tank demo shows you how you can simulate friction in a top down environment, but cars are even more complicated. I think I know a good way to simulate most of it using some strange constraint setups, but without spending a lot of time writing some example code, I think the explanation would just be more confusing than finding some 2D car tutorials on Google.

I used to know a really good 2D car physics tutorial that I would point people to, but it seems to have disappeared from the internet. Sorry. :-\
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Creating a 2D Car?

Postby Aya » Mon Nov 01, 2010 11:49 am

Hi,

oh.. so it's not that easy to do this with chipmunk? Sad.. :(

Do you still have the url of the tutorial you mentioned? Maybe it's in some cache (Google Cache or Archive.org)? :)

Thanks~
Aya
Aya
 
Posts: 3
Joined: Mon Nov 01, 2010 9:48 am

Re: Creating a 2D Car?

Postby slembcke » Mon Nov 01, 2010 4:54 pm

Well it used to be on web.archive.org, but it seems to have disappeared from there as well as of a few months ago. :-\
http://web.archive.org/web/200512041406 ... utcar.html

If you find a new tutorial that's any good let me know though. It's a common enough question that I like to be able to point people in the right direction.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Creating a 2D Car?

Postby Aya » Mon Nov 01, 2010 5:33 pm

Thanks a lot :)

I found the Tutorial and the DemoProject.

Here you can download it:
http://rapidshare.com/files/428387069/C ... rGames.zip


By the way... I looked a bit into the sources of chipmunk to see how it's working.. what do you meant when you said "not designed to work iwth top down 2D physics"? What's the big deal about this? Wouldn't this be just some special joints or something?

Aya~
Aya
 
Posts: 3
Joined: Mon Nov 01, 2010 9:48 am

Re: Creating a 2D Car?

Postby slembcke » Mon Nov 01, 2010 6:21 pm

The problem is friction. In a side view 2D game, friction only happens when objects touch. If an object isn't touching something, then it's in free fall with no friction. With a top down view, things are always sitting on the ground and they always need friction to make them stop moving and spinning. The tank demo shows how you can configure constraints in a somewhat strange way to calculate accurate friction.

The problem for a car is that Chipmunk doesn't currently have the constraints that you would need to simulate tires. Normally, you are going to want isotropic friction, that is friction that is the same amount in any direction. A perfect wheel is effectively anisotropic (not the same in every direction), frictionless when the movement is aligned with the wheel and makes it roll, and generates the normal amount of friction when the direction is perpendicular to the wheel. Chipmunk doesn't really have a constraint that you can configure to do that. A groove joint would almost work, but to use it you'd have to understand the constraints well enough that you might as well just write a new one that wouldn't require clever updates every frame. You also would need a constraint to act as a motor, though in this case you could just copy what the Tank demo does.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Creating a 2D Car?

Postby bram » Tue Apr 03, 2018 2:06 pm

I'm sorry to drag up this old post, but I'm attempting to implement a top down tank, much like the Tank.c demo.
And trying to understand the approach in that demo.

First off, I puzzled by two constraint properties:

There is ErrorBias and there is MaxBias, what is the difference between them?

Next, for each object, two constraints are created: a Pivot and a Gear.
Both have MaxBias set to zero, will they still do something in the sim then?

With a high number of these constraints in the world, will they wear on performance much? Or are these constraints skipped when the body is sleeping?

Thanks.
bram
 
Posts: 24
Joined: Sun May 24, 2009 11:04 pm

Re: Creating a 2D Car?

Postby bram » Tue Apr 03, 2018 4:54 pm

Ok, some experimentations later:

I managed to get a pretty well behaved top-down tank using the following approach:

  • Body for chassis.
  • Body for left track.
  • Body for right track.
  • Use two pins per track to keep it positioned next to the chassis.
  • Use gear with disabled joint correction for angular friction on chassis. (against static body)
  • Use pivot with disabled joint correction for linear friction on both tracks. (against static body)
  • Propel tank by adding forces on the left and right tracks.

If you apply opposite forces on L/R tracks, it will turn in place.
If you apply the same forces, it will travel forwards or backwards.

You can probably do something similar for cars, but with body per wheel, instead of body per track.
bram
 
Posts: 24
Joined: Sun May 24, 2009 11:04 pm

Re: Creating a 2D Car?

Postby bram » Tue Apr 17, 2018 11:56 am

Just leaving an interesting observation here:

When running the debug lib, I got warned with Pin joint being zero length, and pivot would be much more stable.

When I replaced the pin with a pivot, the opposite happened: under fast rotation of the tank, the system would explode. With zero length pins, it would be fine.

So in the end, I decided to put back the Pin joints, and give them a small length, to hold the tracks and chassis together.
bram
 
Posts: 24
Joined: Sun May 24, 2009 11:04 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 7 guests

cron