zoza.blogg.se

Artifact of the week: Collision Box2D

Publicerad 2014-02-13 03:50:00 i 5SD033,

Alright, last week I worked on Learning Box2D and make a project where I would use it together with SFML. We(me and another coder in the group)  had some problems initially  as we first had wrong versions of both above listed "tools". So after we figured out that the SFML that we had been using before we started was 64 bits and that the Box2D we had wasn't compiled for VS 2012 either we got them working together. Box2D is not that hard in it self but it is a bit different because you don't always know what is going on behind the scenes when you first use it. At first I though that it was enough to just write the world, the bodies, set the gravity and draw a "sprite" in the form of a circle and designate it to the position of the body. It was then supposed to fall and when it hit the other box it was supposed to stop. When we started the project it did not do anything at all though.
 
 
 
 
The reason was that you still needed to make some more variables that are used to update the player.
 
 
 
 
After that we had a Ball that was affected by gravity. We then tested to make a simple rectangle to see if the collision would work. It did and so I started to work on Chains. They are made up by multiple vertices that are connected with lines that works very well as walls since its easy to form them to whatever form the room have.
 
To test this I wanted the player to be able to move freely and not just be dragged down by gravity. So I disabled gravity and used the SFML inputs to start with. I couldn't use them without modifying them a bit since it was the Box body i wanted to move and not the SFML "sprite". After that was done I put the chains in the project and hoped that it would work. At that point I had not created a fixture as I thought it was only used for making the bodies visible. But it apparently has to do with collision. After I fixed that something still was wrong. Box2D makes the whole window to have negative y value as it uses the top left corner as the origin instead of the lower left. So when I had set out the positions as positives figures thinking that it was somewhere on the window it was actually above the window. 
 
So here is an example of a chain:
 
 
 
 
 

Kommentarer

Postat av: Hampus Lyman

Publicerad 2014-02-17 19:35:13

Test

Kommentera inlägget här
Publiceras ej

Kategorier

Arkiv

Prenumerera och dela