Box2D is an open-source rigid-body 2D physics simulation library for games, written in C++.

learn more… | top users | synonyms

3
votes
2answers
1k views

Determinism in multiplayer simulation with Box2D, and single computer

I wrote a small test car driving multiplayer game with Box2D using TCP server-client communcations. I ran 1 instance of server.exe and 2 instance of client.exe on the same machine that I code and ...
2
votes
0answers
361 views

how to attach a body to a rope and making it swing to another rope

I've set some ropes (using cocos2d and box2d) and would like to attach a body to one rope in such a way that it can swing to another rope. I am not sure how to go about this. I read making and object ...
0
votes
1answer
414 views

JBox2D - how to get vertex positions?

I've created a triangle for jbox2d... public void createTri(){ PolygonDef shape = new PolygonDef(); shape.density = 2.0f; shape.friction = 0.8f; shape.restitution = 0.3f; ...
3
votes
3answers
584 views

Why does creating dynamic bodies in JBox2D freeze my app?

My game hangs/freezes when I create dynamic bullet objects with Box2D and I don't know why. I am making a game where the main character can shoot bullets by the user tapping on the screen. Each touch ...
3
votes
1answer
139 views

Smoothly move between bodies

I'm not sure if the title is correct (please comment if it is not). I have a sprite (rectangle body), and I'm applying force on it to make it move from left to right and then go backward. The platform ...
0
votes
1answer
254 views

Why set the position of both b2Body and Box2DSprite?

In a game, we add a body for each sprite, the method is: createBodyAtLocation:(CGPoint) forSprite:(Box2DSprite*)sprite In which we create the body and we attach it to the sprite in parameter: ...
0
votes
2answers
1k views

Making body (box2d) a sprite (andengine) in Android

I can't make body (box2d) a sprite (andengine) and at the same time apply MoveModifier to sprite which is body. If i can make just body, it works namely the sprites can collide. If I apply just ...
1
vote
1answer
2k views

Best way to create a level editor in java [closed]

I am creating an iPhone game using cocos2d + box2d that needs a lot of levels. My friends and I are creating the game and most of them have no programming experience and end up with nothing to do. I ...
5
votes
2answers
4k views

Box2dWeb and Images

How do I import and attach a PNG or GIF to a shape in Box2dWeb? The best resource I could find online is at: http://www.jeremyhubble.com/box2d.html However, this "tutorial" doesn't give much ...
1
vote
1answer
653 views

Check for bodies within a specific circle in Box2D

I'm trying to find positions to insert new bodies into my world. For that, I'd like to have a "free" spot where this body wouldn't overlap with anything else. So my plan was to sample "random" ...
1
vote
1answer
544 views

Box2D how to implement a camera?

By now i have this Camera class. package GameObjects; import main.Main; import org.jbox2d.common.Vec2; public class Camera { public int x; public int y; public int sx; public int sy; public ...
1
vote
1answer
591 views

Box2D platformer movement. Should i mess with velocity?

I have a platformer game in which I implemented the movement using a wheel attached to the hero. For jumping I use this: player.body.applyLinearImpulse(new Vec2(0, 30000000), ...
4
votes
5answers
10k views

What is the proper way to remove a box2d body from the world in libgdx?

I'm wondering how to remove the body from the world, because I found an error when I tried. I found following error. java: ...
3
votes
1answer
1k views

How do I implement smooth movement in a Box2D platform game?

I have implemented a character in JBox2D which moves with the help of a wheel rotating at the bottom of it. The movement is the best result I've had 'till now but it's a little glitchy when the ...
4
votes
1answer
1k views

Box2D platformer movement. Are joints a good idea?

So i smashed my brains trying to make my character move. As i wanted later in the game to add explosions and bullets it wasn't a good idea to mess with the velocity and the forces/impulses didn't work ...
1
vote
1answer
1k views

JBox2D applyLinearImpulse doesn't work

So i have this line of code: if(input.isKeyDown(Input.KEY_W)&&canJump()) { body.applyLinearImpulse(new Vec2(0, 30), cam.screenToWorld(body.getPosition())); ...
0
votes
1answer
682 views

box2d resize bodies arround point

I have a compound object, consisting of a b2Body, vector-graphics and a list polygons which describe the b2body's shapes. This object has its own transformation matrix to centralize the storage of ...
1
vote
1answer
4k views

LibGDX Box2D Body and Sprite AND DebugRenderer out of sync

I am having a couple issues with Box2D bodies. I have a GameObject holding a Sprite and Body. I use a ShapeRenderer to draw an outline of the Body's and Sprite's bounding boxes. I also added a ...
5
votes
1answer
3k views

Box2D Difference Between WorldCenter and Position

So this problem has been brothering for a couple of days now. First off, what is the difference between say Body.getWorldCenter() and Body.getPosition(). I heard that WorldCenter might have to do ...
1
vote
1answer
2k views

How would I use JBox2d in Java?

So I did some research and a found Box2d. I then proceeded to download it and the testbed. Now that i have it, I don't know how to properly use it. I'm looking for a clear simple answer on how to ...
4
votes
1answer
695 views

How to make an object fly out of a slingshot?

At the moment I'm improvising a slingshot, the user can click and drag the projectile and let go. The force on the object is calculated by getting the distance between the vector of the slingshots two ...
1
vote
1answer
490 views

How to fake flipping a skeleton in Box2D?

Imagine I have a skeleton — that is a set of bodies held together through various constraints and joints — and I want to flip it. Bodies cannot be flipped in Box2D, so how can I fake that? ...
0
votes
2answers
645 views

Calculate impulse need on object to throw i Y meters into the air, with varying mass

Say I have an object that has a variable mass. Now I want to apply a vertical impulse (straight up into the air) onto the object, so it always flies up to the same height. How do I calculate this? So ...
2
votes
1answer
715 views

Box2D + Love2D (Lua) - Assertion fail with polygon meshes

When I try to create a triangle collider for my game it sometimes leads to an assertion fail. I use the physics engine that comes with love2d (Box2D). That's the error message that appears when the ...
1
vote
5answers
1k views

Errors happen when using World.destroyBody( Body body )

on Android application using libgdx, when I use World.destroyBody( Body body ) method, once in a while the application suddenly shuts down. Is there some setting I need to do with body collision or ...
0
votes
1answer
2k views

Creating lots of sprites dynamically in libgdx

I´m creating Groups that contains Sprites and adding bodies with box2D, but when I create many of this my animation gets very slow. How can I handle it?
1
vote
4answers
2k views

Include Box2D libraries to a cocos2d project (iOS)

I have a problem including box2D to my cocos2d project. I've tried different ways to do it with no success. This is what I've done: I downloaded Box2D (Box2D_v2.2.1) to my project directory. Dragged ...
0
votes
1answer
1k views

b2Body moves without stopping

I got a quite strange bug. It is difficult to explain it in two words, but i'll try to do this in short. My b2Body has restitution, friction, density, mass and collision group. I'm controlling my ...
0
votes
0answers
855 views

Box2d : Sprite display not fit with body when rotated [closed]

I have recently achieved to render box2d Objects, and texture with sprites at where the box2d objects exists. But now I am facing another problem. When I rotate the Box2D object, the sprite gets ...
1
vote
1answer
781 views

Scaling bodies in box2d and libgdx

Is there a way to scale the bodies made from vertexes (like a guitar), i was trying to multiply each vertex point by the scale value but c++ mark an assertion failed, is there a mehtod to do this? I ...
4
votes
1answer
582 views

Multiplayer box2d networking for turn based game

I am currently in the planning stages for a 2D game for mobile devices which I will be making in C++ using cocos2d-x. The game will be turn based and each turn will have a phase in which the physics ...
0
votes
1answer
891 views

Maintain speed in box2D body

I want to delimit my speed and to maintain that speed constantly, but it gets getting higher and if i apply the linear velocity it doesnt bounce :/, Here is te part of my code double fx = ...
2
votes
4answers
4k views

box2d and constant movement

i'm developing a game with a top down view, the players body is a circle. To move the character you need to tap on the screen and it moves to the spot. To achieve this i'm saving the coordinate of ...
0
votes
1answer
822 views

libgdx spite position relative to body

Apologies if this is a reiteration, as I couldn't find another discussion of this over the past couple days. Issue: I'm using libgdx and box2d, and I'm currently updating the sprite's position to ...
2
votes
1answer
2k views

Speed of bodies in Box2D and libgdx

I want to move my bodies at higher speeds, but they have a top speed. I have an Ortoghraphic camera defined at 800x480. My world doesnt have gravity. I apply an impulse of 1000,and a force of 1000 ...
3
votes
1answer
2k views

AndEngine Moving a Connected Texture and Physics Body

In AndEngine, many times we create a TextureRegion for our sprite. We can move this region around the scene but when I connect that region to a physics body I end up being able to use either one to ...
2
votes
1answer
1k views

How to setup JBox2D

I resently downloaded the JBox2D but how do I set this up?.. Its jbox2d-2.1.2.2 All I can see is a bunch of code and folders. Any websites with step by step tutorial?? You know how??
1
vote
1answer
180 views

How to pin a body in case of collision in Box2D or Farseer?

I'm trying to get an understanding for the Box2D/Farseer physics engine by implementing a small air hockey simulation. There, I have the problem that the CPU player attacks the puck, kicks it, but ...
2
votes
2answers
755 views

Efficient Bullet Firing Class

I've been struggling with this for a while. I have been trying to create a bullet pool class for a game I have made that doesn't cause a significant fps drop. I have tried creating a bullet pool ...
0
votes
2answers
3k views

Box2d and sprites

i have really little practice with box2d, but basically it seems to me that it is possible to attach to every sprite (in a 2d game) a box2d shape (that is, a bounding box enclosing the sprite itself) ...
1
vote
3answers
969 views

Unable to find good parameters for behavior of a puck in Farseer

EDIT: I have tried all kinds of variations now. The last one was to adjust the linear velocity in each step: newVel = oldVel * 0.9f - all of this including your proposals kind of work, however in the ...
1
vote
1answer
1k views

Making an object swing from one rope to another

I am trying to make a Tarzan like game with Cocos2D and Box2D. I am having issues with the physics - making an object swing from one rope to another. I am not really sure how to do this. Could anyone ...
2
votes
1answer
230 views

Box 2d and really complex big shapes

I intended to use jbox2d for my project. But as I went deeper into it's manual I'd found out that it supports dynamic objects between 0.1 and 10 meters (if use scaling and assume that 0.1 is smallest ...
4
votes
3answers
652 views

IndexOutOfRangeException on World.Step after enabling/disabling a Farseer physics body?

Earlier, I posted a question asking how to swap fixtures on the fly in a 2D side-scroller using Farseer Physics Engine. The ultimate goal being that the player's physical body changes when the player ...
3
votes
1answer
820 views

How to simulate backspin or topspin in a box2d billiard game?

I am designing a simple billiard game with box2d. I think I can easily simulate hitting left or right side of a ball. Since box2d is not 3D, however, I am not sure how to simulate hitting upper or ...
4
votes
1answer
3k views

sprite display does not match its body in box2d

I found about this using debug renderer. When game starts, everything is in order. But when some collision happens, sprite's rotation is way larger than its body. When sprite and body match is the ...
6
votes
2answers
4k views

how to ignore physics collision of some objects in box2d

I know this sounds silly but I would like some objects to follow physics while others not to collide each other. I tried to achieve them by setting their position exclusively. But then it will ...
3
votes
1answer
296 views

Why does my ball always bounce perpendicular to walls?

I'm using Box2D. I think it's something to do with wall's fixture definition, but when a ball goes toward a wall at a 45 degree angle, I would expect it to bounce off at 135 degrees, but it always ...
2
votes
1answer
698 views

How to encapsulate game objects (entities) in Box2d

I am currently learning Box2d, a 2D physics engine within libgdx. But Box2d seems to be in every game framework these days so I am not really talking about libgdx. I understand Box2d comes with lots ...
1
vote
2answers
595 views

How can I implement a “boost pad” with Farseer/Box2D physics?

I'm trying to implement a boost pad in my XNA game using the Farseer Physics Engine. (This question applies to Box2D too, I would be happy to port working Box2D code to C#.) By "boost pad", I mean an ...