Tag Info

New answers tagged

0

try it like this, mPhysicsWorld.setContactListener(new ContactListener() { @Override public void beginContact(Contact contact) { final Body ballA = (Ball) pContact.getFixtureA().getBody(); final Body ballB = (Ball) pContact.getFixtureB().getBody(); Body bodyFound;//find body of interest from ballA.getUserData(); and ballB.getUserData(); ...


0

get latest source : https://github.com/nicolasgramlich/AndEngine It has the method mPhysicsWorld = new PhysicsWorld(new Vector2(0, 0), false); mPhysicsWorld.setGravity(pGravity); where pGravity is Vector2 object for x and y values for your gravity. like Vector2(0,5).


0

I am using box2d version >2.3.0 where it supports wheel joint and also updated in the andengine source, source:Andengine Example code like, import com.badlogic.gdx.physics.box2d.joints.WheelJointDef WheelJointDef f = new WheelJointDef(); f.initialize(bodyA, bodyB, anchorBody, axis);//axis for suspension feature(Vector2) f.enableMotor=true; ...


0

If you don't want to worry about the pole-vault colliding with anything during the vault, you can simulate it using a simple spring-mass-damper system, and you can just animate the pole deforming artificially. The pole can be considered to be a (very stiff) spring. The rest length of the spring is the length of the pole. This is actually a mathematical model ...


0

You can take a look at the cantilever demo in Box2D. If you use the same strategy you can definitely simulate a pole vault. You'll need pretty stiff revolute joints, and will probably want to set Box2D's iteration count fairly high. Try around 50 or so and lower the number until you see the simulation doesn't perform to your standards. The idea is to just ...


1

In this line ball.applyLinearImpulse(new Vector2(0f, 5000f), ball.getPosition(), true); I think the point where you put force it relative to object position, so you put impule in ball.getPosition() + ball.getPosition() Try to use public void applyForceToCenter(Vector2 force, boolean wake) or ball.applyLinearImpulse(new Vector2(0f, 5000f), new ...


0

SOLVED! Ok so the idea to check if our player body left the body of our path is to count borders playerbody passes. So in contactlistener we make beginContact to add one to some int variable (lets say bordersPassed) and endContact subtracts one from it. So when our player is inside path this variable will always be bigger than 0. When it leaves path it will ...


0

Oh! i got solution by myself... I did the same thing as i mentioned in first comment my question where I attached balls on a big circle body like, Body circleBody ... ;// having large radius //for all balls arranged in hexagon structure foreach BallBody b { WeldJointDef def = new WeldJointDef(); def.initialize(b, circleBody, b.getWorldCenter()); ...


1

Imagine that you have a class that represents a permeable object (in pseudocode): class permeableObject { b2RigidBody body; //this holds the actual box2D rigid body //this is a virtual function; it will be override by derived classes vec2 getExertedForce(vec2 point); //... //functions such as constructor, setBody, etc } Then, you ...


1

If in your game there are only a couple of objects that could possibly go outside of your game limits, you don't have to add rectangles to set the boundaries in your game unless it somehow makes your code cleaner in your case. Efficiency-wise I guess the old fashioned if (object1.Position.X < 0) qualifies as the left boundary in your game. If you have ...


1

If the circles never need to move independently, you can make one body. See here for an example of a hexagon body. I've extracted the relavent bits and pasted them here: import static org.anddev.andengine.extension.physics.box2d.util.constants.PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT; import com.badlogic.gdx.math.Vector2; import ...


0

Should be alright if you are not using too complex shapes or too much bodies at once. If so you could reduce the Box2D frame rate ( lets say the game runs at 60 fps so you can call Box2D update on every second frame and double the ms ) or play around with velocityIterations and positionIterations to maximize performance. I actually used this trick in a ...


0

There exists a manifold from the time BeginContact is called just up until EndContact is called. When EndContact is called the manifold is no longer valid. This means you can store the b2Contact pointer once BeginContact is called. For every game loop that EndContact is not called you can access the b2Contact pointer and query the manifold. This way you ...


0

Okay, So I think you're asking how to do it so here's my Bullet class remodeled to fit a player. Keep in mind this was a bullet class so edit it to fit for your player. Pay close attention to the use of Vectors. public class MovingPlayer { static final float PLAYER_SPEED = 800; Vector3 position, velocity, acceleration; Texture texture; public ...


1

Try fetching the position buffer: Vec2[] positions = m_world.getParticlePositionBuffer(); additionally you might want to grab the colors: ParticleColor[] colors = m_world.getParticleColorBuffer(); Then I would draw the corresponding color at every position using OpenGL. I believe that you can write a very simple shader that would work very well for ...


0

I think you want method 1, not method 2. I assume you a constant turn rate towards the desired heading? In that case, torque, being angular force, is not what you'd want to use here. (You'd need infinite torque to get the initial immediate start, and then infinite torque to stop immediately at the target direction) so the first method is more accurate. ...


0

Okay, I found an answer. You need to set the camera's position directly after calling world.step() and then it works without shifting. world.step(...); camera.position.set(...); camera.update(); (Original Answer)


1

For completeness, I'll document the "reinventing the wheel" approach. I recently wanted to do this too, but I wanted to do it statically (due to some code-structure decisions made before that I didn't want to break). So I didn't want to create a sensor body and World.Step, as previously suggested. Instead, I figured that a convex polygon intersects with a ...


0

The move of the body is due to the air resistance. You should apply a -k*v force to the lower part of the body. Or even more accurate : project the speed vector on the frontmost line of the body : you now have Speed = (sx',sy'). Now apply two different coefficient, k1 and k2, for sx' and sy'. k1 would be the coefficient induced by some air coming face to the ...



Top 50 recent answers are included