[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/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 - Polygon Shapes in Tilemap Based Multi-Layer Levels

Polygon Shapes in Tilemap Based Multi-Layer Levels

Official forum for the .

Polygon Shapes in Tilemap Based Multi-Layer Levels

Postby RPG Hacker » Tue Jul 19, 2011 4:02 pm

Hi there!

I just recently started using Chipmunk Physics since I didn't feel like coding the Physics and Collision Detection for my game myself. I'm using the FreePascal binding, which means the version I'm using is 5.3.2 (so several new functions aren't available to me yet).

Anyways, in my game I have support for an unlimited amount of layers, which can also use tilemaps. The main purpose of this is to have moving level segments, . I thought about a way of utilizing this system using Chipmunk. My idea was to let each layer have it's own Body (or Static Body, if a newer version of the binding gets released) with each tile being a Polygon Shape. That way I could easily edit a tile while a level is being progressed and I could easily assign certain properties to each tile.

However: In the documentation it is said that Polygon Shapes use the most performance. Since I'm planning to have somewhat big levels in my game and don't feel like always removing all Polygon Shapes that are offscreen (especially since I want a very few sprites to continue progressing, even when offscreen) I wonder if using this kind of system would reqiures too much performance. After all having two ore more big layers in a level would mean lots of Polygon Shapes. I don't want to start coding a system that won't work out, anyways.

I also wonder if when using multiple Static Bodies like that in a level the Static Bodies would influence each other (like pushing each other aside or something like that). Right now it probably doesn't matter, since this version of the binding doesn't support custom Static Bodies yet and I have to add the Shapes seperately, anyways. I'd still like to know, in case a new version is released.

Also I'd like to know if anyone has a good method for moving layers like that around. Directly setting the position vector does work, but the sprites that are currently on the layer don't move with it correctly. If moving a layer down, for example, the sprites start falling and landing on it over and over. Since I don't add the layers' Bodies to the Space, but only their Polygon Shapes, I guess I can't use most of the special Body functions, either, or can I?

I'd really appreciate any suggestion.
User avatar
RPG Hacker
 
Posts: 4
Joined: Mon Jul 18, 2011 2:16 pm
Location: Kaperich, Germany

Re: Polygon Shapes in Tilemap Based Multi-Layer Levels

Postby slembcke » Tue Jul 19, 2011 7:34 pm

Well collisions with static shapes are largely free. They don't ever have to be updated because they don't move, and they aren't checked against other static shapes. A shape per tile might use a lot of memory though.

However when you start moving an entire layer with hundreds of shapes attached to it, it would get probably get pretty expensive. This isn't the sort of thing that Chipmunk's collision detection is tuned for. It's sort of a pain to do, but you would be much better off tracing around the edges of your tiles using a small set of line segments. That would be a lot less expensive, but it really just comes down to how many collision shapes you have active at a time.
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: Polygon Shapes in Tilemap Based Multi-Layer Levels

Postby RPG Hacker » Wed Jul 20, 2011 4:23 am

User avatar
RPG Hacker
 
Posts: 4
Joined: Mon Jul 18, 2011 2:16 pm
Location: Kaperich, Germany

Re: Polygon Shapes in Tilemap Based Multi-Layer Levels

Postby slembcke » Wed Jul 20, 2011 8:58 am

Yes, things like moving platforms are easy enough. Basically you just create an infinite mass rogue body. (rogue == don't add it to the space because you'll simulate it yourself). Then update the position and velocity each frame. The velocity must equal (newPosition - oldPosition)/timestep or objects will mush into or ping off the surface.
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: Polygon Shapes in Tilemap Based Multi-Layer Levels

Postby RPG Hacker » Wed Jul 20, 2011 2:23 pm

Wait... so would the same thing work with a complete layer if I replaced the Static Shapes with regular Shapes? After all they're also Rogue Bodies. I know that using lots of regular Shapes would cost a lot of performance, but I could make it so that only a very few tiles use regular shapes. Like, for example, only the tiles you can actually stand on and only on layers that actually move (or have a different scroll speed than x1). I guess moving layers usually don't turn out as big as regular layers, anyways, therefore I wouldn't have lots of collision Shapes to simulate. Would that work?

Also I have another question. Let's say I wanted to make a solid block of 16x16 pixels and wanted to prevent small sprites to get stuck in it by a bug or whatever. In other words: A "filled in" block. Could I use Segment Shapes for this with a thickness of 16, or do I get the thickness value wrong? And do Block Shapes or Polygon Shapes work, or do they only create the outlines of the block?
User avatar
RPG Hacker
 
Posts: 4
Joined: Mon Jul 18, 2011 2:16 pm
Location: Kaperich, Germany

Re: Polygon Shapes in Tilemap Based Multi-Layer Levels

Postby slembcke » Wed Jul 20, 2011 3:44 pm

No. Static shapes never check for collisions against anything. Normal shapes check for collisions amongst themselves, then against the static shapes. So although a moving layer like that isn't really static, it would be cheaper to reindex all of the shapes each frame manually than to have Chipmunk treat them as normal shapes.

The problem is the sheer number of moving shapes, each one has to have it's collision detection data updated every single frame. Anything you can do to cut that number down is good. Chipmunk performs all of it's collision detection in world space, as that's the fastest way to do it in the general case. Very few physics games have massive numbers of objects attached to a single moving body.

"fat" segment shapes are pill shaped, not rectangular. You would have to use a polygon shape instead.
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: Polygon Shapes in Tilemap Based Multi-Layer Levels

Postby RPG Hacker » Wed Jul 20, 2011 4:17 pm

User avatar
RPG Hacker
 
Posts: 4
Joined: Mon Jul 18, 2011 2:16 pm
Location: Kaperich, Germany

Re: Polygon Shapes in Tilemap Based Multi-Layer Levels

Postby slembcke » Wed Jul 20, 2011 4:49 pm

Yes sorry. I misread your question, polygons and circles are solid, filled shapes that objects can't get stuck inside unless they get unsolvably pinned between two or more of them.
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: Polygon Shapes in Tilemap Based Multi-Layer Levels

Postby moxie » Thu Jul 28, 2011 4:47 pm

What if they are unsolvably pinned between two or more? What techniques can I use to get them unstuck?
moxie
 
Posts: 1
Joined: Thu Jul 28, 2011 4:43 pm

Re: Polygon Shapes in Tilemap Based Multi-Layer Levels

Postby slembcke » Thu Jul 28, 2011 9:36 pm

Not much you can do there except yank it out using an even bigger force. The forces from pinning something between two objects are never quite infinite, so it's always possible for another collision/constraint/force to get them out. It usually looks bad though.

Detecting that an object is being crushed is probably a much better solution.
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 0 guests

cron