# Tag Info

21

From my little experience with box2d in libgdx, it can sometimes be difficult to isolate and resolve issues with exceptions which was only worsened by the latest port. Pre 2.2.1, I could easily remove bodies from the world without synchronization issues like you are experiencing but after migrating to the libgdx build that supported 2.2.1, I started seeing ...

15

When the ball (red trajectory curve) hits a block higher up (blue rectangle), it will be moving slower than when it hit a block lower down (green rectangle). Hence why it doesn't bounce any higher than where it came from. Physically, this makes sense. Doodle Jump obviously isn't physically accurate. If you want an effect like in Doodle Jump where the ...

15

After banging my head against this problem for a day I found a wonderful tutorial on the very subject over at Sion Dream. I knew there was a way to use object layers! In a nutshell, create an objects layer on your map (Tiled, Tide and the tutorial author's pick, Gleed, all provide this function), draw the shapes you want your Box2d static bodies to be, then ...

14

Given a "root" curve, here's how you might generate block vertices. The root curve is in the middle, in black. Its control points are shown with red Xs. In short: I made a Bézier and sampled it (at a configurable rate). I then found the perpendicular vector of the vector from each sample to the next, normalised it, and scaled it to to a (configurable) half-...

14

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 me to play around with the RUBE editor to find a nice solution. Here's what I came up with: Setup 1 Let's start with the simpler one on the left. It has the ...

13

Fundamentally, it looks like snow because the particles are round and they don't convey motion in any way. Rain drops are typically seen as elongated droplets, even to the point at which they are lines rather than particles. Think of a scene where you are looking out of a window at a rainstorm: you're not seeing individual drops suspended in the air, you're ...

11

Read up on collision filtering in the Box2D manual: Collision filtering allows you to prevent collision between fixtures. For example, say you make a character that rides a bicycle. You want the bicycle to collide with the terrain and the character to collide with the terrain, but you don't want the character to collide with the bicycle (because ...

11

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 scattered in a whole lot of files, so it's a bit big to put here. See below for an explanation of the technique. How? I used ImageMagick, Potrace, Node.js (with ...

10

I wrote a series of articles about building a platform game from the ground up using modern technologies and it includes how I handled the simple physics: http://www.wildbunny.co.uk/blog/2011/12/14/how-to-make-a-2d-platform-game-part-2-collision-detection/ However if you want something more high-tech it's entirely possible to approach this using full a ...

10

First off, what is the difference between say Body.getWorldCenter() and Body.getPosition(). Body.getWorldCenter() is the center of gravity. Body.getPosition() is the center of the AABB. For a simple box or circle they will be the same however if your body is unbalanced (ex. multiple fixtures /w different densities) they will differ. Also try setting your ...

10

The mechanics for air hockey are not particularly deep, so it wouldn't take much to generate reasonable behavior. Think of the movement of the paddle as comprised of several different types of movement: Wander - to some extent people simply move the paddle around, both left and right and forward and back to keep the enemy guessing. Defend - blocking the ...

9

Most APIs represent the Sprite's origin in local space, not in world space. This is supported by libgdx's documentation which states: A Sprite also has an origin around which rotations and scaling are performed (that is, the origin is not modified by rotation and scaling). The origin is given relative to the bottom left corner of the Sprite, its position. ...

9

You are generally responsible for rendering the state of your box2d world - the "userData trick" you refer to is not really to do with the box2d framework. userData is a placeholder for arbitrary data that you want to associate to a body. This could be anything - a string, function, object, etc. This data is typically used to help you render your world ...

9

When we rotate a object in 2d, each corner is a vector (x,y) away from the center. That vector has an angle. Get the offset of the selected corner from the center: cornerOffset.x = corner.x - center.x; cornerOffset.y = corner.y - center.y; To calculate this angle we do something like this in AS3 / Java angle = Math.Atan2(corner.y - center.y, corner.x - ...

9

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... This is the solution: void SceneView::centerOn(const QPointF &pos) { if (mScene) { mScene->setX(int(-(pos.x() - width() / 2))); mScene->setY(int(-(pos.y() - ...

7

Collision detection in 2D is so damn simple I don't know why you would even bother using a physics engine in the first place. And since all handling forces are straight forward or on a curve (no falling, altering diagnals etc.) Personally it's a no brainer to me which you should pick. Making your own is simple. Collision: account for the 3 possible ...

7

Steering behaviors work very well in combination with a physics-engine, as they are usually implemented in a way that they return a "steering force" which can then be applied to your physics-body. To make a unit follow a path, you could use Seek to go from path-node to path-node (make sure to avoid overshoot) and then use Arrival at the last node in your ...

7

The first argument of applyLinearImpulse is the vector which is the strength of the force/impulse. So just change it to something else rather than 0,0 and your object should fly.

7

One possible solution is as follow: Fix the rotation angle for the box Box2D doesn't have angle joints, but setting the body definition with the property fixedRotation = true allows it to maintain a constant angle of rotation like the angle joint. High maximum torque for the motor's joint The maximum torque for the motor in the revolute joint needs to be ...

7

Tried also to create a breakout clone, but stopped for now, for some other reasons... anyway this is what I learned so far, during development. Use Meters instead of Pixels, Box2D uses MKS (meters, kilograms, and seconds) so when you have a Viewport of e.g. 1280x720 , this would be a length 1,28km. Then your Ball must have an outrageous speed to be "fast" ...

7

But I need to use images in the game as body... not shapes.. In Box2D, you will need to create shapes anyway, you can't really go without them. A body is composed of fixtures and a fixture is a shape, that's it. Here is the official Box2D manual if you want to read more about those concepts. anyone please explain me the steps to use images as a body As ...

7

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) \\ sin(2\theta)&=\frac{dg}{v_0^2} \\ arcsin(sin(2\theta))&=arcsin(\frac{dg}{v_0^2}) \\ 2\theta&=arcsin(\frac{dg}{v_0^2}) \\ \theta&=(arcsin(\frac{dg}...

7

I worked out a closed formula to calculate the velocity v' after some elapsed time t with a given linearDamping d and original velocity v: v' = v*exp(-d*t) To calculate how much time is needed to reach a given velocity v': t = ln(v' / v) / (-d) Using the parameters from the question: t = ln(1 / 10) / (-0.5) = 4.605 The object needs 4,6 seconds to ...

6

In JBox2d, to remove at the correct time: public class Main { World world; ... public void update() //your game loop { ... //do all actual update loop stuff, including detection of collision/death/destruction for (Entity entity : manager.entitiesToRemove) { world.destroyBody(entity.body); //this might be ...

6

I would model the balloon as a circle shape physics-body and use ApplyForce to apply an upward force to the body. If the applied force is negative(gravity * mass), then the balloon should be standing still in the air. Applying a stronger force will cause the balloon to move upwards. You can then connect another body to the balloon using joints (eg. a ...

6

You may be interested in Physics Body Editor. That's an open-source tool handling bodies with multiple fixtures. A big update is in progress, and next revision will support complex dynamic objects made of multiple rigid bodies linked with custom joints, as well as a scripting support for directly testing your bodies. Hope you'll like it ;)

6

First off; I am not familiar with box2D and may not have the right terminology for physics. But storing the top/backspin should be as simple as storing a 2d vector for the potential velocity the ball is "carrying" from when the spin started. Then on collision detection you perform the normal collision and after that you apply the spin. Some tweaking would be ...

6

Don't use the distance. Instead, subtract the fork position vector from the pull position vector and use (some constant multiple of) that as the projectile's velocity. This will automatically scale appropriately for the pull distance. (Actually, it should possibly be squared — I'm not sure what the exact physics of a projectile accelerated by a slingshot ...

6

I suggest using a sensor. Create a circular body of the size of you choosing at the location you desire. Set the Sensor flag to true. Leave it there for a step. (The delta can be 0 units) See if the sensors isTouching flag is set to true. box2d Manual Sometimes game logic needs to know when two fixtures overlap yet there should be no collision ...

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