[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/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 - Dragging car on ground

Dragging car on ground

Official forum for the .

Dragging car on ground

Postby Decept » Tue Oct 13, 2009 7:32 am

In my iPhone game, I have created a car very similar to the one in the moonbuggy example that rolls on a flat ground (static line shape). I want to be able to drag the car forward/backward on the ground using touches/mouse and the wheels should roll correctly due to friction. I have tried several approaches but none worked perfectly.
These are the two best approaches so far:

1. Not adding the car body to the space. Keep track of how much the mouse point has moved on the x-axis and then drag the car itself by updating the horizontal position and velocity of the car body. This works except that for some reason the wheels are lagging behind in movement. They catch up as soon as I stop dragging.

2. Create a mouse body like in the examples but updating only the x-value and with the same y-position as the car body. Constrain the mouse body to the car body (which is in space). The problem here is that the car can bounce around, probably because of the wheels acting on car body's rotation.

I like the first approach more because I can control the sitiuation better. But just can't get the wheels to move along correctly.

Any ideas on this problem? I've been at it for many hours now and I'm out of ideas.
Decept
 
Posts: 14
Joined: Tue Oct 13, 2009 2:38 am

Re: Dragging car on ground

Postby slembcke » Tue Oct 13, 2009 10:17 am

Search for cpMouse on the forums if you want to continue using 4.x. The trunk code contains a more robust version of mouse interaction based on some new joint stuff if you want to move to the latest code.
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: Dragging car on ground

Postby Decept » Tue Oct 13, 2009 10:55 am

sorry, I should have mentioned that I'm using the trunk already. One of the few changes I made to the car from the moonbuggy example is that I swapped the joints for constraints.
Decept
 
Posts: 14
Joined: Tue Oct 13, 2009 2:38 am

Re: Dragging car on ground

Postby Decept » Thu Oct 15, 2009 6:06 am

Any ideas why the wheels are lagging behind the car in my first approach? Each wheel is constrained by a pin joint from the side and a damped spring from above. Shouldn't the pin joint stop the wheel from going straight sideways?
Decept
 
Posts: 14
Joined: Tue Oct 13, 2009 2:38 am

Re: Dragging car on ground

Postby slembcke » Thu Oct 15, 2009 10:01 am

My guess is that you are calculating the velocity incorrectly. If the velocity you are calculating is too small (did you remember to divide by the timestep?) it will be mostly up to the position correction to pull the wheels along. The position correction is really only supposed to be correcting small errors and looks mushy or damped when correcting large errors.
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: Dragging car on ground

Postby Decept » Fri Oct 16, 2009 1:39 am

Decept
 
Posts: 14
Joined: Tue Oct 13, 2009 2:38 am

Re: Dragging car on ground

Postby slembcke » Fri Oct 16, 2009 8:31 am

Not sure exactly, but part of the problem is most likely due to the coarseness of your position and velocity updates. You are stepping several times based on a single position and velocity change. You should smooth out the position change and apply it and the velocity each step. Otherwise you are going from moving for a couple of steps to completely stopped the next time your loop happens. User input coming from the OS is very coarse, it gathers them up and sends them only a handful of times per second and not every step. The physics does not like jumpiness that.
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: Dragging car on ground

Postby Decept » Fri Oct 16, 2009 10:00 am

Decept
 
Posts: 14
Joined: Tue Oct 13, 2009 2:38 am

Re: Dragging car on ground

Postby slembcke » Fri Oct 16, 2009 10:24 am

Two more potential problems with the new code you posted. The important part is that the velocity is smoothed and recalculated per step, the position follows the velocity naturally. Secondly, if the body of the car is still added to the space, that means that it's position is getting updated twice, once by you and once by the space shortly after. Calculating the velocity alone and letting the space handle the position is a much better idea.

Honestly, having tried this before myself, the solution really is to use a constraint to move things around.
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: Dragging car on ground

Postby Decept » Mon Oct 19, 2009 7:40 am

I did as you suggested and only set the velocity and let the space update the position. But the result is exactly the same, with the wheels lagging behind.
I have not had much success with using a constraint to move the car as the car is now totally under the control of the space. The result is that you can make the car bounce around because of the forces from the springs. The wheels are updated correctly though.
Decept
 
Posts: 14
Joined: Tue Oct 13, 2009 2:38 am

Next

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 2 guests

cron