Questions tagged [box2d]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
21 views

problems with displaying sfml textures

I have created a kind of framework for a game that combines box2d and sfml. All game scenes are stored in the Game class. The scenes also contain information about static and dynamic objects: ...
-1
votes
0answers
50 views

box2d.Fixture contact

In box2d, there is a class b2ContactListener, consisting of virtual functions and kind of allowing you to override what will be executed when collisions are detected. I have redefined the functions as ...
0
votes
1answer
55 views

How do I correctly use userData in Box2d?

Many guides used userData. But with the source of Box2d I have, I don't see the SetUserData functions in the code as I see them in the guides. After understanding ...
0
votes
0answers
35 views

Compute normal of collision between two bodies, when multiple fixtures touch

I have a body made of multiple fixtures. Sometimes, when another body collides with it, Box2D detects contacts between more than one fixture. The figure illustrates this: the blue body is made of two ...
0
votes
1answer
38 views

Simulating a small world with Box2D

I would like to use Box2D to simulate a small world, with entity sizes around 1cm (0.01m), some smaller than that. Box2D's FAQ says twice: Your moving objects should be between 0.1 - 10 meters. You ...
2
votes
0answers
41 views

Object stuck against an obstacle still pushes other objects away

I have an object pinned against the ground by a revolute joint. A motor on the joint makes the object spin. Sometimes the object becomes stuck pushing against a static body. When it happens the object ...
0
votes
2answers
52 views

Collision filtering in Box2D: running out of bits

I have a physical simulation on the streets of a city. The simulation is 2D but in a few points it could develop on multiple "layers": for instance bridges or underground tunnels. I may have ...
1
vote
2answers
103 views

Simulating a rocket out of control in Box2D

In the void of space, a spaceship releases a rectangle shaped space-torpedo. In half a second, it starts its rocket engine and goes straight until something get in its way, and then boom! The code ...
1
vote
0answers
39 views

Avoiding jitter when snapping diagonal movement to a pixel grid

Whats the best way to be rendering the locations of objects in box2D in such a way that there no stuttering on movement beyond 8-directions. I'm looking to have object strictly snap to the pixels but ...
2
votes
1answer
64 views

What could effectively affect the falling speed of a b2Body?

I tried to set up a test demo to see if Box2D physics are working. It works, but I have one small problem: I cannot seem to get the dynamic b2Body to fall faster. I ...
0
votes
0answers
28 views

Box2D calculate distance in certain direction

I'm writing simple AI genetic learning for a 2d car. To do so I need sensors surrounding my car so I can get distance to closest obstacle in every direction. (Picture 1) Picture 1: I need every of the ...
0
votes
1answer
44 views

Way to check overlaps of a collider2d that's not set to "is trigger" in Unity

I have a system where physics2d objects are spawned and I need to know when they spawn outside of a region defined by a box collider set to "is Trigger". Using onTriggerEnter and ...
1
vote
0answers
19 views

How to create a joint, where the rotation of one object is relative to the other?

I would like to create a top down view scene, with one rectangle (top) is on top of an other (base). There is a joint, where ...
0
votes
0answers
75 views

libGDX box2D not setting user data

I am working about box2D. Even if I set userData, when I retrieve it via getUserData(), it returns null. Using debugger, I noticed that object passed to setUserData() is not null, but on the next ...
0
votes
1answer
35 views

Box2d: High screen resolution / frequency causes high friction?

I'm using Cocos Creator with (built-in) box2d for physics. Recently our game behaves weirdly on our new device Galaxy S20 Ultra 5G - which has screen size = 1440 x 3200 - frequency = 120Hz. After stop ...
2
votes
1answer
105 views

Predicting trajectory of Box2D physics body using both: linear dumping and gravity

I would like to calculate position of physics body after some time because of predicting shots trajectory in my game. I found some great answer here where Iter Ator provides equation to calculate ...
1
vote
4answers
158 views

When an object is launched off-screen, is there any way to know if it's coming back?

In this scene, the object becomes invisible and then comes back In this scene, the object becomes invisible but does not come back Is there any way I can tell if an object will come back when it ...
0
votes
0answers
19 views

Discrepancy in Box2D Flash applied impulse

I have two clients. Player A, and Player B. What Player B sees in his screen is a mirrored version of what Player A sees. This is a carrom game, hence the mirroring. Does anyone know why even if I ...
0
votes
0answers
48 views

box2D vs manual collision handling in libGDX

I am developing a fairly simple game with Zelda-style physics where the only moving objects will be characters and other entities, however I am using a randomly generated (all in code, no .tmx) tile ...
3
votes
1answer
950 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
0answers
60 views

Box2d on authoritative server for Unity client

I'm creating a multiplayer platform and shooting game in unity, using unity2d's own physics system (box2d). But the truth is that I am quite lost in the creation of an authoritative server in c ++. I ...
1
vote
1answer
77 views

how to set volume of sound depending on the impulse a body receives in Libgdx / Box2d?

I am trying to set the volume of a bouncing sound of a ball depending on how hard the ball hits something. so the harder the ball hits a wall or a ground the more loud the bounce sound. I couldn't ...
0
votes
0answers
83 views

Optimizing Box2D for a couple hundred static bodies

I searched but could not find anything similar (Yet) around the web, so here I am asking my question: In my game I use around 3 to 4 hundred static bodies with like 10 dynamic bodies in the Box2D ...
1
vote
1answer
159 views

setTransform() Box2D physics not working

It's my first time posting here! I'm working on a top-down shooter game in LibGDX and Box2D (so gravity is set to (0, 0)). At the moment, to move my character, I'm ...
0
votes
0answers
18 views

Body's initial velocity is too fast when created after minimax algo

I don't know if my question is right but I cannot address the real problem. I am dropping connect 4 game chips under gravity but when I apply minimax with a depth of 3, it starts with great velocity. ...
0
votes
1answer
57 views

Box2d: crash on createBody in beginContact callback

I am getting this error on creating body in contactListener ...
1
vote
1answer
62 views

Apply impulse in direction line is pointing with force proportional to the length of line

I have a line perpetually pointed at the mouse and originating at the player, but the length is limited to a certain value. I also can create a circular object on demand in Box2D (specifically the ...
0
votes
1answer
64 views

Box2d RopeJoint bug - fix or alternative solution?

What I am trying to do is to create rope game. Below you can find a movie how it looks like now. https://youtu.be/QTULCGNF70I I am using RopeJoint and I am reducing maxLength each frame to be able ...
0
votes
1answer
50 views

Planck.js (rewritten of Box2D.js) - 8 direction box movement

I have a box in Planck.js. I want to move this box with some keys. How can I do that? My code: ...
0
votes
0answers
58 views

Box2d ContactListener function. Problem calling a function on the collided objects

I created a ContactListener class which derives from b2ContactListener. I am following the excellent tutorials found here: https://www.iforce2d.net/b2dtut/collision-callbacks Collisions are detected ...
0
votes
0answers
152 views

How do I make a hitbox for a sword in a top-down game?

Context: I'm using Box2D through LibGDX in Java. The sword and the player are in separate classes. Both extend LibGDX's Sprite class. I've got a sword attached to my character that swings when I ...
0
votes
1answer
112 views

Box2d Raycast C++. Always returning false? (trying to check if player is grounded)

I'm trying to add Box2d to my C++/SFML platformer game. I have my ground tiles with a b2staticBody. And the player character is b2_dynamicBody. My usual method to check if player is grounded is to ...
0
votes
0answers
64 views

LibGDX Box2D, how to play an animation once, then set the state back

So, I've got some animations in LibGDX that I want to get running. Currently, the walking animations work perfectly, but attacking doesn't. I want the attack animation to play once, then set the State ...
0
votes
1answer
69 views

testPoint not working - libgdx

I'm making a game like angry birds with LibGDX and box2d in which I want to drag a ball (instead of the bird) back before releasing it. I deploy with testPoint function: when I touch down the ...
0
votes
1answer
157 views

How to damp the velocity of an object only in one axis in Box2d?

I want to damp the velocity of a ball linearly on the x-axis. but when applying linear damping on the ball, the damping also applies in the y-axis which makes it look like its floating. I tried to ...
1
vote
0answers
43 views

What would be the best way to let Box2D handle collision on different (simulated) heights?

I'm working on a 2D top-down game but we are also using a Z coordinate. This is to simulate the effect of 3D/height. Now the player can walk under a bridge and also over a bridge. The next thing I did ...
0
votes
1answer
50 views

How do i draw sprite on fixture position?

...
0
votes
2answers
150 views

Assertion b2Assert(m_bodyCount > 0) showing an error

I have the following code for deleting a Box2D body: ...
1
vote
1answer
96 views

How to keep the value of angle between 0 and PI in box2d

In box2d, if i rotate an object multiple times in clockwise or anti clockwise direction, the value of angle ( body.getAngle() ) keeps on increasing. Like at start it is at 0 radians, then 1.57(90 deg),...
0
votes
1answer
60 views

LibGDX “EXCEPTION_ACCESS_VIOLATION” error when recreating previously disposed Box2DLights light

I just installed the Box2DLights dependency for LibGDX and I added a cave with 2 ConeLights inside. The first time I render the cave, everything works as expected. Then when I exit the cave, I make ...
0
votes
1answer
352 views

What scaling system to use in Box2d?

I'm worried about this Caution box from the Box2d manual: Box2D is tuned for MKS units. Keep the size of moving objects roughly between 0.1 and 10 meters. You'll need to use some scaling system ...
0
votes
1answer
61 views

how to apply force/impulse perpendicular to the moving direction in box2d

How can i apply or impulse to an object perpendicular to its moving direction in a top down game. Like if object is moving up, i press left or right, then force or impulse should be applied to left or ...
0
votes
3answers
151 views

Finding an angle between two bodies

I am trying to find angle between vectors a and b. But the cosine for some reason is not within +/- 1, that means that it is not possible to find an angle between a car and a pedestrian... Any help ...
0
votes
0answers
27 views

How to limit Box2D bodies to only be affected on 1 axis

I have a side scrolling game, where I am randomly placing trees, bushes etc.. I would like these bodies to fall ( To Align with the ground ) but not to slide. What is the best way to achieve this and ...
1
vote
0answers
112 views

Rolling a circle around a square

I am stuck on a simple Box2D task. I have a box and a ball (in top-down view so no gravity), and I would like the ball to roll around the box. Here is my code. Basically now I am trying to detect ...
0
votes
1answer
186 views

Pybox2d Collision detection explanation

Hi I am working on a PyBox2D game and it became quite complex and I need to learn about collisions, so I made this very simple script in order to learn collision setting more effectively, however I am ...
1
vote
0answers
475 views

How to make a top down 2D ball rolling

I am developing a top down game similar to 8 pool billard with libgdx and box2d. How do i make a 2d ball texture look like its rolling when force is applied like this: So it feels actually 3d ? For ...
3
votes
0answers
101 views

Game runs at different speeds in Chrome versus Firefox

I am using Box2D for physics on the server side. Player position is updated on the server, so there is nothing the client can do except give input. But running game in Chrome only, the player moves ...
0
votes
1answer
94 views

Box2D Weird collision behavior

I'll let the gif speak first. As you can see, the small cube just kinda floats there like it has a forcefield. This weird glitch only happens with small cubes, smaller than 60 pixels for some reason. ...

1
2 3 4 5
16