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
1
vote
0answers
13 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
10 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 ...
-1
votes
0answers
25 views

Libgdx and Box2D with android studio: Why isn't the ball responding to touch inputs?

public void create () { . . . . . Gdx.input.setInputProcessor(new PlayerControl(camera, BallBody)); } ...
0
votes
1answer
20 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
68 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
123 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
17 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
40 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
353 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
51 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
45 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
59 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
70 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
25 views

Unable to rotate box2d body with torque if revolute joint introduced

I created a simple body (PLAYER) which, as speed increased the angle of the body increases slightly. I set the torque property based on velocity, to change the body's angle, and it looks like the ...
0
votes
0answers
26 views

Can problems arise in client-server network games due to the permanent sending of messages?

I'm my Client-Server-based game I'm using the following stack: libGDX (Engine) Ashley (ECS) KryoNet (Networking) Box2D (Physics) Server =========> Client I've got a Box2DSyncSendingSystem on ...
0
votes
0answers
7 views
0
votes
0answers
16 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
0answers
17 views

Pouring balls into a shape to fill it densely

I am trying to making a physics game similar to Angry Birds Dream Blast (ABDB), using box2d. I need to fill the play field with balls/chips. Problems: I have a few of them: I do not understand how ...
0
votes
1answer
43 views

Box2d: crash on createBody in beginContact callback

I am getting this error on creating body in contactListener ...
1
vote
1answer
44 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
56 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
36 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
51 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
131 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
95 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
49 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
58 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
100 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
37 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
49 views

How do i draw sprite on fixture position?

...
0
votes
2answers
113 views

Assertion b2Assert(m_bodyCount > 0) showing an error

I have the following code for deleting a Box2D body: ...
0
votes
0answers
57 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
44 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
271 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
44 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
119 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
25 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
98 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
142 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
389 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
94 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
83 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. ...
0
votes
1answer
278 views

How do make a box collider align with a line renderer continuously?

I am having the issue of aligning my BoxCollider2D with my linerenderer. I am trying to have a laser shoot using: ...
1
vote
2answers
173 views

Disposing objects when changing screens

I'm making my first game with LibGDX and Box2D, and I've realized that the memory used increases when I change screens. It starts from 150MB and progressively reaches 850. How should I deal with this? ...
0
votes
0answers
57 views

Dealing with ghost vertices of Kinematic bodies in Box2D

I'm using LibGDX and Box2D and I want to have multiple falling platforms in a row which will fall sequentially as the player runs on them, like in the picture below. (the shapes are parsed from Tiled) ...
0
votes
2answers
324 views

Box2d: Destroy body or setActive to false?

What is better practice when a body goes out of screen, to destroy the body or just setActive(false)? I guess in terms of memory it is better to destroy it and free the memory, but is destroying ...
0
votes
0answers
101 views

Box2D - Proper way to simulate player's body and feet

I'm new to LibGDX and Box2D, and I'm trying to create my player's body but got some issues. I've created the ground as a ChainShape, and my player as a Rectangle. I want to attach a fixture for its ...
0
votes
0answers
22 views

Best practice for frequent sending webSocket/Socketio/webRCT data [duplicate]

I already done game template for classic platformer. I use matter.js for physics and my own override draw functions. Everything works fine. Next stage is to make it multiplayer. I interest is it good ...
0
votes
1answer
39 views

LIBGDX - Artifacts when scaling background image

I've got a problem with libgdx. First off, im working with libgdx and box2d on a little physics game. Im using the aproach mentioned in this answer and thereby setting my camera to some smallish ...
1
vote
0answers
65 views

Is it better to combine or leave alone 2D polygons

I'm making a modular system for a 2D spaceship arcade like game, the user builds their own ship with equilateral triangles to make more complex shapes. When the ships are small it's no problem, but as ...

1
2 3 4 5
16