Questions tagged [box2d]
Box2D is an open-source rigid-body 2D physics simulation library for games, written in C++, with ports in various languages
63
questions
76
votes
5
answers
44k
views
Good 2D Platformer Physics [closed]
I have a basic character controller set up for a 2D platformer with Box2D, and I'm starting to tweak it to try to make it feel good. Physics engines have a lot of knobs to tweak, and it's not clear to ...
7
votes
5
answers
31k
views
How do I destroy a Box2D body on contact without getting an IsLocked assertion error?
I get this error when attempting to remove a body from the world:
java:
/var/lib/hudson/jobs/libgdx/workspace/trunk/gdx/jni/Box2D/Dynamics/b2World.cpp:134:
void b2World::DestroyBody(b2Body*): ...
4
votes
1
answer
3k
views
How to develop both a client and headless server together in Unity
I'm making a multiplayer 2d shooter platformer in unity. And after studying the different options to program an authoritarian server and with the great help that many of you have already provided me ...
0
votes
2
answers
898
views
Floating point precision issue with Box2D
I'm using Box2D and I am putting edge tiles as b2Bodies so that the tile world can have physics:
The problem is that there are 3 b2_kinematic bodies under the player right beside each other.
Every so ...
13
votes
5
answers
6k
views
2D Rope Collision Detection
I'm wanting to create a rope that can collide with objects like in the following youtube video:
2D Game Physics Rope
I'm thinking that you implement the verlet integration which uses points and ...
6
votes
2
answers
1k
views
Show path of a body of where it should go after linear impulse is applied
I am making a game with Andengine and Box2D. I have a dynamic body and I apply linear impulse on the body to move it around when the user have touched the screen.
Now I want to show the path where ...
3
votes
1
answer
893
views
Using Box2D for range detection?
I have two entities. One has a sword, one has a bow and arrow. When the bow entity is 100 units away, he needs to begin attacking. Likewise, when the sword entity is 10 units away, he needs to begin ...
2
votes
3
answers
2k
views
Box2d bodies that are really close together, are getting “stuck”
I'm using a tiled tmx map, and I created a class that adds bodies to each tile within a certain layer. This has been working great so far except for when a character or an enemy moves around on the ...
20
votes
4
answers
8k
views
Best strategy (tried and tested) for using Box2D in a real-time multiplayer game? [duplicate]
I am currently tackling real-time multiplayer physics updates for a game engine I am writing. My question is how best to use Box2D for networked physics. If I run the simulation on the server, should ...
12
votes
1
answer
3k
views
How do I make a curved surface out of rectangular blocks?
For a Peggle-like game, I want to make blocks that follow a curve, like this:
The blocks would then disappear as the ball hits them.
I managed to draw some horizontally, but I'm having trouble ...
9
votes
2
answers
17k
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 ...
9
votes
1
answer
5k
views
Basic Box2D collision detection
I don't understand how to listen for collisions in Cocos2D/Box2D. Say I have two dynamic circle bodies. One is very small and the other is relatively large. When the small circle collides w/ the ...
8
votes
1
answer
8k
views
Why is my sprite displayed offset from its Box2D body?
I found out about this using a debug renderer. When the game starts, everything is in order. But when a collision happens, the sprite's rotation is way larger than its body. The sprite and body match ...
8
votes
3
answers
21k
views
How can I convert a tilemap to a Box2D world?
I want to use Box2D physics and lighting with a .tmx map. How can I "convert" a tilemap to Box2D world? My basic idea is to go through the tiles on the map and ...
6
votes
1
answer
10k
views
Box2D recommended step, velocity and position iterations
Here in this article there is a nice explanation that velocity iterations and position iterations settings affect the way bodies will react when they collide, and step affects on speed and how gravity ...
6
votes
2
answers
2k
views
How do I turn an image into a Box2D physics object?
I'm using Box2D for a Game Programming course, and I was wondering if it is possible to choose the best shape and size of shape for the rigidbody/fixture for a sprite based on its transparency.
I've ...
4
votes
2
answers
3k
views
How do I set angular velocity/torque so that it's pointing to velocity/direction?
Right now, when I spawn a shootable object, it goes like this:
Because I just set it's angle to this:
...
3
votes
2
answers
2k
views
Why does my position interpolation code result in "jumpy" motion?
I am developing an android game with box2d and use a fixed timestep system for advancing the physics.
However as I use this system it requires the box2d positions to be interpolates. I read this ...
3
votes
2
answers
3k
views
What does linearDamping mean in Box2D?
If I set linearDamping on a body, it's velocity will be decreased slowly, until it stops.
The documentation says, that the units are 1/time, which is unclear for me.
If the velocity of a body is 10 m/...
3
votes
1
answer
5k
views
Movement and rotation of bodies in top down game
We are developing a 2D top down game with libgdx using the included box2d as physics engine.
We don't want our bodies to accelerate but to instantly move with the wanted velocity.
The bodies are ...
3
votes
1
answer
2k
views
How to create a projectile motion of a cannonball in top down view?
Objective
To move the bullet with projectile motion to specific destination by touch point.
In the below image is an example of a bullet which has a projectile motion. On my observation, the bullet ...
2
votes
1
answer
918
views
Why do my Box2D bodies not fall, even though world.step is called?
I have SFML set up with a Box2D world that has gravity, but my bodies won't
move. I std::cout'ed the position of the body in the game loop, but it's always at <...
1
vote
1
answer
3k
views
Box2d contant speed before and after collision
I want to make my body fly at constant speed, how to make it fly at constant speed before and after collision? I set restitution of my body to 1.0 but after some direct and powerful collisions my ...
12
votes
3
answers
4k
views
How do you do AI path following within a 2d physics engine like farseer/box2d?
I'm in the process of moving a 2d top down game I've been working on into a proper rigid body physics engine like Farseer. Up until now, I had just hacked together my own physics code where needed.
I'...
9
votes
2
answers
5k
views
Box 2D Set Origin
I'm trying to set the origin of a box2d shape. By default, a shape rotates around the center. But I'm trying to get it to rotate around the left of the shape. Like a clock for example.
I've heard of ...
9
votes
1
answer
509
views
How can I copy or back-calculate definitions for an entire b2World?
I'm working on a platformer where I'd like to be able to move or copy bodies between multiple Box2D b2Worlds. The desire has cropped up three times now - moving objects between documents in my editor, ...
7
votes
2
answers
4k
views
How to create an extensible rope in Box2D?
Let's say I'm trying to create a ninja lowering himself down a rope, or pulling himself back up, all whilst he might be swinging from side to side or hit by objects. Basically like http://ninja....
6
votes
1
answer
4k
views
Generating a physics body for 2D Worms-like Terrain
I wrote a processing sketch that generates hills for a scorched earth clone, like this:
I'm trying to figure out how to make this a physics object in libgdx, but I'm having problems figuring out how ...
6
votes
3
answers
1k
views
Rectangles render with gaps in between them (Box2D)
Right now I create my boxes where 1 meter is 85 pixels. Gravity is 10. And
...
5
votes
1
answer
1k
views
generate box2d bodies from isometric tiled map
I followed the tutorial here to generate box2d bodies from a tiled map and that worked fine.... for orthogonal tiled maps. Unfortunately isometric maps use their own coordinate system where (0, 0) is ...
5
votes
3
answers
4k
views
How to make Box2D bodies automatically return to a initial rotation
I have two long Box2D bodies, that can collide while moving one of them around with MouseJoint. I want them to try to hold their position and rotation.
Blue body is moved using MouseJoint (yellow) ...
5
votes
2
answers
921
views
Detecting a ledge in Box2D [duplicate]
Possible Duplicate:
Detect Open Space in Farseer
How do I detect ledges?
I'm making a 2D platformer with Box2D. The player needs to be able to grab onto a ledge and pull him/herself up.
Right ...
5
votes
3
answers
2k
views
Semi Fixed-timestep ported to javascript
In Gaffer's "Fix Your Timestep!" article, the author explains how to free your physics' loop from the paint one.
Here is the final code, written in C:
...
4
votes
4
answers
2k
views
Libgdx body passing through block then fall on it
I'm using libgdx and its physic engine Box2d. My question is : how could I make my box2d body go through a block , ignore the first collison than make the block active so the ball can fall onto it. A ...
4
votes
2
answers
3k
views
Collision Filtering in Box2D
I have four bodies in my Box2D World. Each are polygon shape, with some physics parameters.
Now when the game start, I need one of the bodies from the World (BodyA) to not be allowed to collide with ...
4
votes
3
answers
886
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 ...
4
votes
1
answer
2k
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 ...
4
votes
4
answers
5k
views
Fix joint length in Box2D?
I'm having some difficulties with Box2D DistanceJoints, I'm trying to create a rope using DistanceJoints connecting some bodies together but the length of joints between bodies change due to weight of ...
4
votes
1
answer
515
views
Cocos2d: Tongue effect like in Munch Time
I'm wanting to do a tongue effect for my character like the one in Munch Time( shown in pic ). The player does some action and his tongue attaches to the nearest platform.
I'm thinking this is ...
4
votes
1
answer
3k
views
Problem Implementing Texture on Libgdx Mesh of Randomized Terrain
I'm having problems understanding how to apply a texture to a non-rectangular object. The following code creates textures such as this:
from the debug renderer I think I've got the physical shape of ...
3
votes
1
answer
2k
views
How to implement rotating rectangle around circle in libGDX Box2D?
I want to implement rotating rectangle around cicrle in such way, that circle has no rotation, and rectangle has, and I could myself control rotation of this rectangle (I mean set its angular velocity)...
3
votes
1
answer
2k
views
Stopping on a slope in Box2d
I am creating a simple platformer using Box2d. I've implemented a variant of the technique described here.
To make the player character move more 'platformer-like' I want him to stop on (shallow) ...
3
votes
1
answer
975
views
determine collision angle on a rotating body
update: new diagram and updated description
I have a contact listener set up to try and determine the side that a collision happened at relative to the a bodies rotation. One way to solve this is to ...
3
votes
2
answers
2k
views
When and how should I apply forces in a Cocos2D + Box2D game?
I have some small circles just rolling across the bottom of the screen in my Cocos2D/Box2D iOS app. The bodies are dynamic... so I make them roll by applying a horizontal force to the center of mass (...
2
votes
1
answer
1k
views
How to make a character in a Box2D world jump faster?
I have a question about using Box2D to simulate a physics-platformer.
I manage to make the character move to the right and left, and jumping as well. However, jumping seems extremely slow when ...
2
votes
2
answers
1k
views
LibGDX: Is there a maximum amount of vertices for a PolygonShape?
When you use PolygonShape.set(Vector2[] vertices), is there a limit of vertices of the array which is passed to the method?
2
votes
1
answer
2k
views
Camera scrolling and game boundaries
I am making a platformer game in JBox2D and LWJGL that has a scrolling camera, but I have hit a wall with the boundaries of the camera.
Essentially what I have right now is a Box2D world that is ...
2
votes
1
answer
796
views
How do I make a rope from point A to B in Box2D?
I need to make a rope (preferably not elastic) from one point to the next in Box2D. If it helps, I'm trying to develop one of those 2D Spiderman games, like this: http://www.gamesbutler.com/game/4327/...
2
votes
2
answers
2k
views
Simple 2D Flight Physics with Box2D
I'm trying to build a simple side scroller with an airplane being the player. As such, I want to build simple flight controls with simple but realistic-feeling physics. I'm making use of cocos2D and ...
2
votes
1
answer
1k
views
Why might a body suddenly stop while moving on continue platform?
I have a 32x32 sprite and I make some to be platform like this
...