Box2D Forums

It is currently Sun Oct 19, 2014 9:19 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Wed Apr 22, 2009 2:07 am 
Offline

Joined: Wed Apr 22, 2009 2:01 am
Posts: 3
I'm making a platformer right now, and I've noticed a bad problem.

Basically, right now I'm creating each tile as a separate static box, and they form a smooth surface. As the character slides around it will frequently get stuck between two tiles. I don't want to change the shape of the character (a box); do you guys know how to solve this?


Top
 Profile  
 
PostPosted: Wed Apr 22, 2009 2:19 am 
Offline

Joined: Wed Apr 22, 2009 2:01 am
Posts: 3
Oh, and I'd like to not group together tiles to form a big box, if possible, because that'd make other parts of my code more complex.


Top
 Profile  
 
PostPosted: Wed Apr 22, 2009 4:31 am 
Offline

Joined: Sun Apr 19, 2009 6:00 am
Posts: 9
You have to change the shape of the box. Try this:
Code:
(-0.95,1.0)
(-1.0,0.95)
(-1.0,-0.95)
(-0.95,-1.0)
(0.95,-1.0)
(1.0,-0.95)
(1.0,0.95)
(0.95,1.0)


Top
 Profile  
 
PostPosted: Thu Apr 30, 2009 12:27 am 
Offline

Joined: Wed Apr 22, 2009 2:01 am
Posts: 3
matrebatre wrote:
You have to change the shape of the box. Try this:
Code:
(-0.95,1.0)
(-1.0,0.95)
(-1.0,-0.95)
(-0.95,-1.0)
(0.95,-1.0)
(1.0,-0.95)
(1.0,0.95)
(0.95,1.0)


While that solves one problem, that creates another; the character sliding around (which now has the 8-sided figure matrebre suggested) is now irregularly jumping up. I tried to replace the tiles' shapes with the 8-sided figure, but it doesn't work either. What should I do?


Top
 Profile  
 
PostPosted: Thu Apr 30, 2009 3:33 am 
Offline

Joined: Sun Sep 23, 2007 2:35 pm
Posts: 803
This comes up often enough that I created a "Known Issues" page in the wiki and added an entry for it: http://www.box2d.org/wiki/index.php?title=Known_Issues

The options (at least until the engine gets changed to support some other way of doing it) are pretty much either a) make your character round on the bottom, which it sounds like you tried and it didn't work too well, b) process the shapes before you create them so that you don't have gaps (I realize this is not always possible), or c) use edge shapes instead.


Top
 Profile  
 
PostPosted: Thu Apr 30, 2009 9:31 pm 
Offline

Joined: Fri Sep 21, 2007 6:40 pm
Posts: 40
I ran into this problem a few days ago. I found that the dog-eared solution didn't work for me, nor did trying to add circular shapes at the corners: that just result in me "popping" at the problem spots. So I switched over to using the b2edgeChain stuff entirely for all my ground/wall needs and it works really well (it's also easier to make level terrain by plotting points and drawing line segments). It's in the 2.0.2 branch though which last I checked wasn't available for download on the main website. You can download it instead from the Sourceforge SVN repository (http://box2d.svn.sourceforge.net/viewvc/box2d/).


Top
 Profile  
 
PostPosted: Wed Oct 21, 2009 1:47 pm 
Offline

Joined: Wed Jun 10, 2009 9:19 am
Posts: 36
I'm having this exact same problem. I have two pretty huge (compared to my player character) ground tiles, static, and placed exactly next to each other, not overlapping, but with no distance between them. My character is moved along them with ApplyImpulse. Similarly to the kind of problems I had in my own crappy platformer engine, the player sometimes gets stuck at the point where the two boxes meet.

Can anyone describe exactly what's happening here? I'm curious to know why it actually happens, and if there's any 'error' that can be added to specific objects' collisions with other objects, so they more or less slip out of them. Don't get me wrong, I'm not wishing that a 'fake' characteristic is part of the engine, but just that maybe there's something in there we can use in this situation.

I'm also about to try and implement a condition for my character climbing shallow stairs. I want the character to be able to walk up any higher object that he comes to, which is lower than, say, his knees. Does anyone have advice on how this can be done well? Ironically, it would probably automatically fix the previous problem, as what I'm saying is, mount the next horizontal object if it is realistically low enough for a human character to be able to step up to without jumping.


Top
 Profile  
 
PostPosted: Mon Aug 09, 2010 4:34 am 
Offline

Joined: Wed Jun 10, 2009 9:19 am
Posts: 36
Hi folks, I just wanted to know - has this 'known issue' been addressed? Do Erin or Boris consider it an issue? What are the thoughts?

I'm still having trouble with it. I've uploaded a couple of examples, stripped down to the most basic environment in which this issue happens for me.

Note that the game I'm building is in XNA, using Box2D.XNA, but since I've used Box2D several times before in Flash/AS3, I thought it a good idea to try and remove the possibility that it's something I'm doing wrong in Box2D.XNA or that it's something not quite right with the library port.

Here they are:

http://www.shauncampbell.co.uk/flash/box2d/
http://www.shauncampbell.co.uk/flash/box2d/octagonal.html

Use the arrow keys to move (Up to jump). You can still use the mouse to click and drag the box. Arrow key controls use body.GetLinearVelocity().x += movementSpeed. Note that in the AS3 version, the linear velocity is returned as a reference (meaning this isn't a mistake!).

So, you can obviously test the issue by dragging the box along the boxes. That means it's not only due to the implementation of character movement by manipulating linear velocity directly.

Use the button at the top if you want to toggle fixed rotation on the player body. This can make the issue a little clearer - with fixed rotation off, the body simply stops, but it's obvious when turning fixed rotation off that it's actually getting slightly stuck on something, and with rotation on it just rolls on past it - both behaviours are unnacceptable for my game.

I've been considering using b2EdgeChain, as the octagonal or circular body methods don't really work for me. I don't want to continue on knowing that the player can move to the edge of a platform and slide off it when not expecting it. The player won't be an obvious rectangle but I think it's more likely the player will assume that's how it's treated, rather than it being circular or octagonal.)

My problem with b2EdgeChain is that I've already build a level editor that works really well with tiles. It uses brushes, erasers, and tiles can be selected in groups and dragged around. If I have to do passes over these tiles before 'compiling' the level (outputting to XML), it's going to detract from actually getting on and building the game. Besides that, isn't it going to become quite complex to fully 'join' the whole world together as one edge. This problem can occur when pushing into a wall as you fall, too, so it's basically going to have to be done on every wall, every edge. We thought about implementing gravity switching, so I'd have to go and do this on ceilings, too.

Another thought on b2EdgeChain - if I was to, in my editor, step through and calculate some b2EdgeChain that goes around the whole level and any 'islands' inside the level, what would happen if any of those yielded concave shapes? Do b2EdgeChains handle concave shapes? I know that you can't create a rigid body using PolygonShape with vertices laid out in concave. Does this mean I'd have to not only calculate my edges, but then split them up where they go concave? Then, I'd have gaps again, which the player would surely be able to get stuck in, as per the original setup I had.


Top
 Profile  
 
PostPosted: Mon Aug 09, 2010 11:18 am 
Offline

Joined: Sun Sep 23, 2007 2:35 pm
Posts: 803
No, this still has not been addressed, I'm not sure if it's in the works yet.

Another solution, the one I would recommend esp. if you're using simple square/rectangular tiles everywhere, is to just merge any horizontally adjacent tiles into longer rectangles. This takes very little effort code-wise and should solve the problem.


Top
 Profile  
 
PostPosted: Mon Aug 09, 2010 11:34 am 
Offline

Joined: Wed Jun 10, 2009 9:19 am
Posts: 36
I'd mentioned in my previous post that this was an option, but I know it's only going to partly patch up the issue. It still would leave enough issues that I'm not going to bother doing it - this issue occurs vertically too - so if the player's falling down alongside a wall and you have even two horizontal static bodies, then the player pushes into that wall, there's a chance the player can get stuck the same way, thereby 'landing' on the wall. This is potentially even worse than it happening horizontally. So, I could patch together vertical collections of boxes. But, there's still the possibility that there are shapes I can't connect all together. I talked about using b2EdgeChain to just 'walk round' any exposed surface and close it off where it meets the start of the next, and so on, so that every surface that faces the player doesn't have an end point - if it's an 'island' sitting as a few square tiles (set there in the editor), then instead of having a few separate tile bodies, make a b2EdgeChain that follows around its edges and make it loop. If that's what's really recommended, it sounds a bit of a hassle. Besides, does that work with concave bodies? Wouldn't those have to be split up anyway? Unless that's done at time of collision, which doesn't sound likely, because then you're constantly executing the algorithm that detects concave shapes and where to split them to make everything convex.

Also, what about for non-static bodies? Or bodies that perhaps change mode from static to dynamic. Imagine a trap or puzzle where you have a lever somewhere that causes two simple square static bodies at either side of a verge become dynamic, and slide along at whatever velocity until they collide in the middle, at which point they stop - and perhaps become static again until the lever is next activated. You then have the same situation, where there are two perfectly horizontally aligned static bodies that you can attempt to walk over and get stuck in.

There is the option for the person making a level or environment to have the collision areas (i.e. static physics bodies) completely separate from the graphics, so that they can be placed where they suit best, but that kind of ruins the usability of the editor for someone not quite clued up on the Box2D engine and any issues that arise due to design/implementation choices in the game, along with issues in the Box2D engine.

I don't want to continue with these methods that only partly solve the problem, as this project is more than just a means to an end where the game is what's desired and the physics engine will 'do'. I'm now more interested in getting this sorted, or it'll just haunt me for ever.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Group