Helly guys,
I need help again, but now, i got a different problem.
I built a matrix 5x5 (just to test) to store my blocks (as u can see in the image). So, when i going to "walk" over this blocks, i got some undesirable collisions, it happens in each division of 2 or 3 blocks (left division and right division).
Anyone knows why it happens and how can i fix it?
PS: I thought about giving up the idea to use physics in my game, it's giving me much headache (whenerver i got an unexpected problem).
Block collision - problems in detection
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Block collision - problems in detection
- Attachments
-
MyFarmFactory.love
- (148.07 KiB) Downloaded 169 times
Re: Block collision - problems in detection
Hi. First off let me just say that Box2D is probably not the best tool for side-scrollers especially if physics is not the main emphasis on your game. Box2D is great for physics gameplay were controls are generally loose. If you want super-tight controls Box2D will drive you insane.
Your character is standing on block A but it's also colliding with block B at the same time.
Box2D can't figure out the order in which these two collisions should be resolved.
What happens is, collision with B is resolved first, so your character is pushed to the RIGHT and then the collision with box A is resolved second so your character is pushed UP.
This is caused by the Box2D collision solver so you have to work around it.
The simplest solution is to create your platforms as a single shape rather than an array of boxes.
Another (uglier) approach is to create overlapping trapezoids instead of boxes for inner blocks:
Obviously corner blocks can't be trapezoids.
This is kinda tacky but I'll use the chance to plug my FizzX lib based on earlier project by Taehl.
I believe you meant to say 'array' instead of matrix.Schbaltz wrote:I built a matrix 5x5 (just to test) to store my blocks (as u can see in the image). So,

This is because your character's shape collides with the ledge of the box that's right next to it.when i going to "walk" over this blocks, i got some undesirable collisions, it happens in each division of 2 or 3 blocks (left division and right division).
Anyone knows why it happens and how can i fix it?
Code: Select all
__
<---/ \
__ ____\__/___
| B | A |
| | |
Box2D can't figure out the order in which these two collisions should be resolved.
What happens is, collision with B is resolved first, so your character is pushed to the RIGHT and then the collision with box A is resolved second so your character is pushed UP.
This is caused by the Box2D collision solver so you have to work around it.
The simplest solution is to create your platforms as a single shape rather than an array of boxes.
Another (uglier) approach is to create overlapping trapezoids instead of boxes for inner blocks:
Code: Select all
___ ___ ___
/ \
/_____\
Don't get discouraged. Physics and collisions is tightly related to game controls which is usually the most important thing in action games.PS: I thought about giving up the idea to use physics in my game, it's giving me much headache (whenerver i got an unexpected problem).
This is kinda tacky but I'll use the chance to plug my FizzX lib based on earlier project by Taehl.

Re: Block collision - problems in detection
Hey Schbaltz.
One solution is to use a circle instead of a rectangle. I change around your code a bit to do this.
I don't know how 'strict' you want the collision detection to be so maybe you would prefer the rectangle shape.
anyway...
The circle has setFixedRotation set to true so it rolls instead of slides over the blocks.
and i gave the body setAngularDamping( 1000 ) to make it slow down quicker.
hope this helps
One solution is to use a circle instead of a rectangle. I change around your code a bit to do this.
I don't know how 'strict' you want the collision detection to be so maybe you would prefer the rectangle shape.
anyway...
The circle has setFixedRotation set to true so it rolls instead of slides over the blocks.
and i gave the body setAngularDamping( 1000 ) to make it slow down quicker.
hope this helps

- Attachments
-
MyFarmFactory.love
- (152 KiB) Downloaded 185 times
wat ya mean she's in another castle!?
Re: Block collision - problems in detection
Ivan,
Thx very much for your explanation, my game needs sigle blocks because it's "breakable" (like terraria)...
Sorry my bad english, brazillian here
Juno,
This is a good solution man! i change my code to:
It works fine!!!
I'm so excited with this game, i have many ideas to implement... the next step is create "breakable" blocks, but this is easy to do. ASAP i'll post the results in the "projects" topic...
Thx very much guys!!!
Thx very much for your explanation, my game needs sigle blocks because it's "breakable" (like terraria)...
Sorry my bad english, brazillian here

Juno,
This is a good solution man! i change my code to:
Code: Select all
instance.shape = love.physics.newCircleShape(instance.bounds.width / 2,instance.bounds.height / 2,instance.bounds.height / 2)
instance.body:setAngularDamping(1000)
I'm so excited with this game, i have many ideas to implement... the next step is create "breakable" blocks, but this is easy to do. ASAP i'll post the results in the "projects" topic...
Thx very much guys!!!
Re: Block collision - problems in detection
One of the problem cases with circle collision shapes is when your character reaches the end of a platform and you change direction back towards the middle of the platform. Since you're using a circle with fixed rotation the shape will get stuck on the corner of the platform with his/her legs dangling in the air.

Code: Select all
___ circle
<-- / \
-----| |
\___/
box |
|
Who is online
Users browsing this forum: Google [Bot] and 3 guests