Hot answers tagged

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 ...
Anko - inactive in protest's user avatar
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....
Mitch's user avatar
  • 295
8 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 ...
Iter Ator's user avatar
  • 257
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) \\ ...
starikcetin's user avatar
  • 5,245
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 ...
DMGregory's user avatar
  • 130k
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, ...
Anko - inactive in protest's user avatar
5 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 ...
Bram's user avatar
  • 3,709
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 ...
mklingen's user avatar
  • 591
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 ...
dadylonglegs's 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 ...
Anko - inactive in protest's user avatar
4 votes

Java Libgdx Attaching Sprite to Box2D Body

Two (simple) solutions could look something like this: Give the player class a Sprite (best). ...
Charanor's user avatar
  • 7,790
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 ...
Bálint's user avatar
  • 14.8k
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 ...
Louis Langholtz's 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 ...
Philipp's user avatar
  • 118k
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 ...
Stephane Hockenhull's user avatar
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 ...
Sean Carey's user avatar
3 votes

How to make sure that when two bodies collide, there is only one collision detection on box2d?

I recommend you look into how box2D works. Anyways use one of the below, most likely BeginContact. ...
ClassicThunder's user avatar
3 votes
Accepted

Box2d: Is there a way to have collisions but ignore the accompanying forces?

I figured it out. Each dynamic body (what you control) must have an accompanying kinetic body "shadow". Their collisions must be set up as follows: each dynamic body only collides with other dynamic ...
jpanda109's user avatar
3 votes

Data oriented design in physics engine

What you should optimize for is probably best shown in and around slide 40 of this presentation: http://www.slideshare.net/cellperformance/gdc15-code-clinic The idea is to prevent the code from doing ...
snake5's user avatar
  • 3,588
3 votes
Accepted

How do i set gravity towards a point in the centre in AndEngine with Box2D?

You don't do it by trying to set the global gravity. Instead you set the global gravity to zero and then you calculate the force that your gravity would affect the object with and apply that. Pseudo-...
bornander's user avatar
  • 4,431
3 votes
Accepted

How to implement rotating rectangle around circle in libGDX Box2D?

You can achieve this using a RevoluteJoint to anchor the "motor" to a point in the world, and a WeldJoint to anchor the rotating ...
bornander's user avatar
  • 4,431
3 votes

Should I compute impact damage with energy or momentum?

You could use both, depending on case and need. Both are valid and both occur together. The difference in your case is apparently how you define loss of energy, ie. what is more convenient and ...
Stormwind's user avatar
  • 1,053
3 votes

Dealing with collisions across adjacent static bodies

Have you considered playing the sound when the direction of the ball changes? Or like add that as a condition, in addition to the already "collide with object" condition.
Skitskraj's user avatar
3 votes

Most optimal way to load 2D world

I don't think you can fix that "loading" issue, if your game has to open a file from HDD, load the content, parse it and draw it there's nothing to do that could speed it up. I would say that, the ...
PRDeving's user avatar
  • 755
3 votes
Accepted

How to avoid 2d enemy to see through walls

You only need to do two things: check if there is line of sight (raycast between the player and enemy) and if the angle of that ray is within the field of view (using atan2 to get an angle or using ...
David's user avatar
  • 86
3 votes
Accepted

Creating a player that can hold different items

I'd say, don't sweat it. Your character's two hands are independent of one another, the two items groups have distinct interfaces and are meant to be used in different ways. Just use a properly-typed ...
Quentin's user avatar
  • 1,168
3 votes

How does mass work in Box2D

As Bálint explained, mass in Box2D basically works according to Newton's laws of motion. Sounds like what you're really after though is how mass works in Box2D in practical programmatic terms. As you'...
Louis Langholtz's user avatar
3 votes
Accepted

How detect collision between two bodies?

Answer What you are looking for is called a Collision Callback. There is a great tutorial written by iforce2d on the topic, so I'll just give the key details here. The strategy in Box2d is to ...
NauticalMile's user avatar
  • 1,695
3 votes
Accepted

What's wrong with using physics engine in 2d platformer?

It's not necessarily a completely terrible idea but there are significant cons to weigh against the pros you mention. In particular, the physics in a platformer character usually isn't totally (or ...
jhocking's user avatar
  • 15.7k

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