2022 Developer Survey is open! Take survey.

Hot answers tagged

15 votes
Accepted

How can I simulate a floating character in Box2D?

UPDATE: over the years I've become a bit more knowledgeable, and I realized Setup 2 can be modeled in a simpler way. I've added Setup 3, which I believe is the best solution. Your question inspired ...
user avatar
  • 1,685
10 votes
Accepted

How do I turn an image into a Box2D physics object?

I tried this. It was hard, but I did it. Left is GIMP, top-right is a Box2D debug renderer, bottom-right is a build shell Code repository for reference The full code is on github here. It's ...
user avatar
  • 13.3k
9 votes
Accepted

Why do my game objects jitter when moving the camera?

Ok, that's awkward. My last edit revealed the answer to my problem (that I've been struggling with all day): QGraphicsView casts the camera x/y position to integers....
user avatar
  • 285
7 votes
Accepted

What does linearDamping mean in Box2D?

I worked out a closed formula to calculate the velocity v' after some elapsed time t with a given linearDamping ...
user avatar
  • 247
6 votes
Accepted

Maintaining velocity of free fall body using Box2D in libGDX

Disclaimer: I have not used libgdx or Java before, this answer borrows syntax from the question and official documentation, and the code is untested To make the bodies 'fall' under the influence of ...
user avatar
  • 1,685
6 votes
Accepted

Movement and rotation of bodies in top down game

Simple Solution If you want the body to instantly rotate just call Body::setTransform and pass the current position and the desired angle, don't bother applying ...
user avatar
  • 1,685
6 votes
Accepted

Box2D recommended step, velocity and position iterations

First of all, if you want to avoid aliasing problems, you need to respect the Shannon rule. So you need to take 120FPS or more. Secondly, you don't really need to care, you can simulate at 40 if you ...
user avatar
  • 2,343
6 votes
Accepted

Why is Euler integration sometimes preferred over RK4 even if RK4 is more accurate?

It's very probable that Erin Cato subtly justified the use of the Symplectic Euler over RK4 or another higher order integrator. The author has lots of slides and/or material (e.g. http://gamedevs.org/...
user avatar
  • 3,221
6 votes
Accepted

b2DistanceJoint with frequency equal to 0 vs b2WeldJoint

Thanks for asking Narek. I've struggled with understanding these joints in the past, and I'd like to use this answer to clear up some misconceptions. ...
user avatar
  • 1,685
6 votes
Accepted

How to create a projectile motion of a cannonball in top down view?

From wikipedia: $$d=\frac{v_0^2}{g}sin(2\theta)$$ When you reverse the formula to find the angle from the distance and initial speed, it becomes: $$\eqalign{ d&=\frac{v_0^2}{g}sin(2\theta) \\ ...
user avatar
6 votes
Accepted

How to develop both a client and headless server together in Unity

Myself, I'd recommend keeping the server and client authored in a single Unity project. This minimizes the chance for mistakes where you change something in either the server or client and miss ...
user avatar
  • 112k
5 votes

how do I create a moving type of block like in Mario[box2d]

I tried it out in RUBE and the Prismatic joint works fine for me: What you may not have realized is that you can set joint limits on the prismatic joint, which makes this a lot easier to set up. You ...
user avatar
  • 1,685
5 votes
Accepted

How to optimize a box2d simulation in action game?

Now that I think about it some more, there may be a way. Basic Idea You say you are using a tile-based map, so you might consider implementing tile-based collision detection far away from the player....
user avatar
  • 1,685
5 votes
Accepted

LibGDX Box2DLights shadow offset problem on bodies

This is less a problem with Box2dLights, and more a problem with setting up Box2d collision fixtures to match your sprites. The Box2dLight rays are colliding with the CircleShape fixture you attached ...
user avatar
5 votes

box2d rendering performance degrading extremely even with sleeping bodies?

Yet having these 3500 sleeping static bodies degrades performance to such a degree that even when running the game on my MacBook Pro 2012 in a Genymotion emulator, I get about 5 FPS. As Anko said in ...
user avatar
5 votes
Accepted

In Box2D, what exactly does a fixture represent?

Yep, sounds right. A body abstractly represents a physical entity. A fixture defines its shape, physical properties and which other fixtures it collides with. Technical details in the Box2D manual, ...
user avatar
  • 13.3k
5 votes
Accepted

What is the physics behind a 2D gravity tunnel?

On collision with the field, set gravity to 0. While colliding with the field, multiply your velocity by a number between 0 and 1, like 0.999; This is called "damping", it simulates being inside a ...
user avatar
  • 591
4 votes

How to restrict jumping to a single jump?

The most common approach to this is to detect if the character is standing on a solid surface before allowing them to jump. This restricts players to a single jump since the first jump puts them in ...
user avatar
  • 72.7k
4 votes
Accepted

Body lost a velocity component when hitting a wall

What's happening First of all, note that this behavior is not specific to oblique collisions. Below is an example of two balls colliding head on with a wall. All fixtures have ...
user avatar
  • 1,685
4 votes
Accepted

How do I query a LibGDX Box2DLights "light" and "dark" regions?

I found the solution, so I think I should write here for other ones later. First I download the source code of box2dlights. Then open BaseLight.java and find "segments" member variable. This variable ...
user avatar
4 votes
Accepted

Why do my Box2D bodies not fall, even though world.step is called?

1/60 in your world.Step call is an integer division, which truncates toward zero. The world is being told to step by 0 seconds ...
user avatar
  • 13.3k
4 votes

Java Libgdx Attaching Sprite to Box2D Body

Two (simple) solutions could look something like this: Give the player class a Sprite (best). ...
user avatar
  • 7,609
4 votes

What shape should you use for player collision?

Every collision shape has it's pros and cons: The axis aligned bounding box is very cheap to do collision against, but it's very rough and it's not possible to rotate it, thus it may need to be ...
user avatar
  • 14.5k
4 votes
Accepted

What is inertia in a physics engine?

I believe what we're looking at here more specifically refers to rotational inertia and inverse rotational inertia; not to linear inertia (nor inverse linear inertia). Wikipedia explains that ...
user avatar
4 votes

Should a bowling game use a 2d or a 3d physics engine?

When developing games it is important to separate the game mechanics from the game representation on the screen. The game mechanics of bowling can be simplified to a pure 2d simulation by looking at ...
user avatar
  • 111k
4 votes

Turn a spaceship at a max rate

There's no friction in space so what is happening is actually the proper realistic behaviour: The ship spins faster and faster. If you want to limit rotation speed you can use Body.AngularDamping to ...
user avatar
4 votes

What does linearDamping mean in Box2D?

I looked at the Box2D source code, where it applies damping: v *= b2Clamp(1.0f - h * b->m_linearDamping, 0.0f, 1.0f); So the loss of velocity is certainly not ...
user avatar
  • 3,669
4 votes
Accepted

Predicted trajectory becomes less accurate in a side-on collision

The issue was that the radius that I inputted into the CircleCast was not accurate. Initially, I set the radius to that of the cueball's circlecollider2D, which would be .09f. But since I lowered the ...
user avatar
3 votes

How can I simulate a floating character in Box2D?

NauticalMile's answer is great (and bonus points for the killer animated diagrams). To give an alternate suggestion that doesn't suffer from the same problems (the wheel collision stopping you from ...
user avatar
  • 6,008

Only top scored, non community-wiki answers of a minimum length are eligible