[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/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 - Flipping X of an complex object.

Flipping X of an complex object.

Official forum for the .

Flipping X of an complex object.

Postby Birkemose » Tue Feb 28, 2012 2:55 pm

Hi
I have a small tank running on some terrain, and now I want the tank to be able to drive both ways.
Is it in any way possible to flip the entire object ( bodies, shapes, joints, contraints ) around the X-axis, or should I create a new object?
Birkemose
 
Posts: 30
Joined: Thu Feb 10, 2011 8:45 am

Re: Flipping X of an complex object.

Postby slembcke » Tue Feb 28, 2012 3:15 pm

There isn't really an easy way to do that no. Recreating the object isn't all that easy either as you need to make sure to flip all the shapes (each one is a little different) and all of the constraints (each one is a little different...). You also need to make sure that you aren't flipping the wheel or something through a wall in the process. It's definitely not simple like it is in graphics to just flip the transformation matrix around.

What I've done in the past to get around this is to make the physics models symmetrical. Then it doesn't matter if it's going to the left or right, the physics is the same. All you need to do is flip the sprite for it and nobody is the wiser. The tank you were showing off earlier was already pretty symmetrical, you'd really just need to tell the phase on the gun barrel joint to flip back and forth. It even gives it a nice animation that way as well.

I made a little game prototype once with a fully flippable vehicle for an even crazier example. It's really simple, I just change some of the parameters for the shocks pop the wheels to the other side of the car when it flips over.
http://howlingmoonsoftware.com/extras.php
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: Flipping X of an complex object.

Postby Birkemose » Tue Feb 28, 2012 4:35 pm

Hmm, the ting is, that the asymmetrical design is part of the "tumbler" stragety which prevents the tank from coming to rest upside down.
But you are right so far, that it is only a few parts which actually needs to be changed, and I was wondering if the easiest way would be to create shapes for both ways, and then simply add and remove them to the group, as needed. They are practically without mass anyways.
Birkemose
 
Posts: 30
Joined: Thu Feb 10, 2011 8:45 am

Re: Flipping X of an complex object.

Postby slembcke » Tue Feb 28, 2012 5:27 pm

Yeah, that will work. As long as you remove the object from both the space and the chipmunkObject array it will be fine. If you do one or the other, it will either leave garbage objects in the space or trigger assertions about removing things from a space more than once.
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: Flipping X of an complex object.

Postby Birkemose » Tue Feb 28, 2012 5:34 pm

Thx, that will be the way to do it then, and I will make sure to keep group and space in sync.
Birkemose
 
Posts: 30
Joined: Thu Feb 10, 2011 8:45 am

Re: Flipping X of an complex object.

Postby Birkemose » Wed Feb 29, 2012 4:10 am

Well, it turned out, that removing and adding joints and constraints at runtime, wasn't such a stellar idea. I guess even if I place a constrained body in right position, the constraint isn't "up to speed", so I would probably have to remove the old constraint completely, and add a new one.
In stead I ended up adding both objects which face left, and objects which face right, and then simply ignore collisions on objects facing the wrong way. Downside is simulating 3 bodies, 3 shapes, 2 joints, 2 rotation limiters and 1 gear more than I actually need, but I guess that is a small price to pay.
Birkemose
 
Posts: 30
Joined: Thu Feb 10, 2011 8:45 am


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 5 guests

cron