[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
Chipmunk Physics • View topic - Top-down vehicles

Top-down vehicles

Official forum for the .

Top-down vehicles

Postby patrickC » Sun May 03, 2009 4:41 pm

patrickC
 
Posts: 7
Joined: Sat May 02, 2009 10:55 am

Re: Top-down vehicles

Postby PeskyJ » Sun May 03, 2009 9:35 pm

This is interesting, first to address your main point...

To get different surfaces should be fairly simple, multiply your acceleration value and your torque value by a value between 0 and 1 depending on the traction you want. This will mean your car continues in its current state much more than being affected by forwards drive and steering. However, this assumes you have a relatively low damping that only damps for wind resistance and surface friction.

I suspect you may be using more damping (a low value) because it doesn't sound as if you're manually damping your torque and acceleration, which you should to avoid ever-accelerating angular and forwards velocity (rather than using a lot of global damping). So pick a maximum angular velocity and when actual angular velocity reaches this value, any torque in that direction should be zero. Similarly for acceleration.

To simulate a higher "slow-down" effect when the car is going sideways, use the cosine of the angle between the direction of travel and direction of facing.

Before trying this though you should 'correct' your orientation. I notice from the snippet of code you posted that your car is facing upwards (along the positive Y-axis) when angle is zero. In mathematics the convention is that an angle of zero represents a positive x and zero y and as angle increases positively, the value rotates anti-clockwise. Therefore you should point your car to the right at zero degrees and accelerate it along the x-axis. This will make all the maths work as expected :)

So to get the cosine of the difference between the angles, take the dot product of carBody->rot and normalized carBody->v - this will give you a value from -1 to 1 that you can multiply by a force relative to the magnitude of velocity (i.e. the faster the car is going, the greater the "slow-down" from friction). If you have implemented the different surfaces mentioned above, this value too can be multiplied by the surface traction so slippery surfaces slow it down less.

J
Games games games... I love games. Check out my games:
PeskyJ
 
Posts: 19
Joined: Fri Apr 24, 2009 4:24 pm
Location: Reading, UK

Re: Top-down vehicles

Postby patrickC » Mon May 04, 2009 12:21 pm

patrickC
 
Posts: 7
Joined: Sat May 02, 2009 10:55 am

Re: Top-down vehicles

Postby PeskyJ » Mon May 04, 2009 12:58 pm

You need to fix your cars orientation before any of the maths will work as expected. Point it to the right for an angle of zero.

The dot product of two unit vectors gives the cosine of the angle between the vectors, not the angle. The reason you're probably seeing 1 instead of 0 is that your car is 90 degrees out of kilter with the maths. Once your car orientation is fixed, acceleration will be in the positive local X direction, and
lateral friction (when the car is going sideways) will be in the local Y direction.

To damp angular velocity when you stop steering, check your "lost traction" flag and manually damp it very rapidly, except when you've lost traction then damp it slower. You could use the absolute steering value (0 to 1) to damp angular velocity as well as calculating the torque.

You talk about applying a sideways force based on steering, this seems a bit odd because you don't want your car to actually travel sideways due to steering (only due to momentum when you turn). Just apply a forwards force (positive X) and the steering plus the lateral friction should take care of the rest. Unless you want to simulate front-wheel drive in which case it might get really complex with a jointed object on the front dragging the front of the car around instead of the 'cheating' way of turning the body using a torque.
Games games games... I love games. Check out my games:
PeskyJ
 
Posts: 19
Joined: Fri Apr 24, 2009 4:24 pm
Location: Reading, UK

Re: Top-down vehicles

Postby patrickC » Tue May 05, 2009 5:50 pm

patrickC
 
Posts: 7
Joined: Sat May 02, 2009 10:55 am

Re: Top-down vehicles

Postby patrickC » Tue May 26, 2009 5:28 am

patrickC
 
Posts: 7
Joined: Sat May 02, 2009 10:55 am

Re: Top-down vehicles

Postby bennysce » Wed May 27, 2009 2:04 pm

Would be cool to see how your simulation turned out in action. I'm a big fan of top-down racers and I've created this: http://www.roadclubgame.com . No zombies though :)
bennysce
 
Posts: 12
Joined: Sat Sep 27, 2008 3:14 am

Re: Top-down vehicles

Postby codeflakes » Thu May 06, 2010 9:42 am

Hello,

I'm really interested in the full code of the car physics if by any chance the author would agree to share it. It tried to used the snippet from this thread but I don't understand it fully and did not manage to get proper result.
User avatar
codeflakes
 
Posts: 3
Joined: Thu May 06, 2010 9:35 am
Location: Paris

Re: Top-down vehicles

Postby slembcke » Thu May 06, 2010 9:59 am

The original tank driving demo code is in trunk.

http://code.google.com/p/chipmunk-physi ... emo/Tank.c
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


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 8 guests

cron