Search Results

Search found 248 results on 10 pages for 'box2d'.

Page 2/10 | < Previous Page | 1 2 3 4 5 6 7 8 9 10  | Next Page >

  • Box2D Bicycle Wheels Motor Problem - Flash 2.1a

    - by Craig
    I have made a bicycle with Box2D using several polygons for the frame at different angles connected using weld joints, and I have revolute joints on the wheels with a motor. I have made some basic terrain (straight ground and a small ramp) and added keyboard input to control the bicycle with torque to balance it. All of this is done in with Box2D's Debug Draw. When the bicycle is on its back wheel but diagonally forward (kinda like this position - /) the motors just cause it go spinning backwards over when in reality it should either stay on its back wheel or go down onto both wheels. Here's my code the revolute joints: //Front Wheel Joint var frontWheelJointDef:b2RevoluteJointDef = new b2RevoluteJointDef(); frontWheelJointDef.Initialize(frontWheelBody, secondFrameBody, frontWheelBody.GetWorldCenter()); frontWheelJointDef.enableMotor=true; frontWheelJointDef.maxMotorTorque=10000; frontWheelJoint = _world.CreateJoint(frontWheelJointDef) as b2RevoluteJoint; //Rear Wheel Joint var rearWheelJointDef:b2RevoluteJointDef = new b2RevoluteJointDef(); rearWheelJointDef.Initialize(rearWheelBody, firstFrameBody, rearWheelBody.GetWorldCenter()); rearWheelJointDef.enableMotor=true; rearWheelJointDef.maxMotorTorque=10000; rearWheelJoint = _world.CreateJoint(rearWheelJointDef) as b2RevoluteJoint; And here's the relevant part of my update function: // up and down control wheels motor if (up) { motorSpeed-=0.5; } if (down) { motorSpeed += 0.5; } // left and right control cart torque if (left) { middleCentreFrameBody.ApplyTorque( -3); gearBody.ApplyTorque( -3); firstFrameBody.ApplyTorque( -3); secondFrameBody.ApplyTorque( -3); rearWheelToChainBody.ApplyTorque( -3); chainToFrontFrameBody.ApplyTorque( -3); topMiddleFrameBody.ApplyTorque( -3); } if (right) { middleCentreFrameBody.ApplyTorque( 3); gearBody.ApplyTorque( 3); firstFrameBody.ApplyTorque( 3); secondFrameBody.ApplyTorque( 3); rearWheelToChainBody.ApplyTorque( 3); chainToFrontFrameBody.ApplyTorque( 3); topMiddleFrameBody.ApplyTorque( 3); } // motor friction motorSpeed*=0.99; // motor max speed if (motorSpeed>100) { motorSpeed=100; } rearWheelJoint.SetMotorSpeed(motorSpeed); frontWheelJoint.SetMotorSpeed(motorSpeed); Any ideas what might be causing this? Thanks

    Read the article

  • Climbing boxes in box2D

    - by Rothens
    I've just stepped into the world of Box2D with libgdx. I've already made a stack of boxes: They are dropped randomly ontop of each other. What I'd like to achieve is to make a character, that could freely climb on the boxes, (He can grip on the boxes anywhere, not just on the side/top of a box) but his weight affects the stack as well, so the boxes could fall down. My google-fu failed me... Is there any way to make this possible?

    Read the article

  • Attach my sprite with Box2d

    - by user919496
    I'm coding Javascript(HTML5) with Box2D. And I want to ask how to attach Sprite with Box2D. This is function My sprite: function My_Sprite() { this.m_Image = new Image(); this.m_Position = new Vector2D(0,0); this.m_CurFrame = 0; this.m_ColFrame = 0; this.m_Size = new Vector2D(0,0); this.m_Scale = new Vector2D(0,0); this.m_Rotation = 0; } My_Sprite.prototype.constructor = function (_Image_SRC) { this.m_Image.src = _Image_SRC; } My_Sprite.prototype.constructor = function (_Image_SRC,_Size,_Col) { this.m_Image.src = _Image_SRC; this.m_Size = _Size; this.m_ColFrame = _Col; this.m_Scale = new Vector2D(1, 1); } My_Sprite.prototype.Draw = function (context) { context.drawImage(this.m_Image, this.m_Size.X * (this.m_CurFrame % this.m_ColFrame), this.m_Size.Y * parseInt(this.m_CurFrame / this.m_ColFrame), this.m_Size.X, this.m_Size.Y, this.m_Position.X, this.m_Position.Y, this.m_Size.X * this.m_Scale.X, this.m_Size.Y * this.m_Scale.Y ); } and this is function Object : function Circle(type, angle, size) { // Circle.prototype = new My_Object(); // Circle.prototype.constructor = Circle; // Circle.prototype.parent = My_Object.prototype; this.m_den = 1.0; this.m_fri = 0.5; this.m_res = 0.2; fixDef.density = this.m_den; fixDef.friction = this.m_fri; fixDef.restitution = this.m_res; fixDef.shape = new b2PolygonShape; bodyDef.type = type; bodyDef.angle = angle; bodyDef.userData = m_spriteCircle; fixDef.shape = new b2CircleShape( Radius / SCALE //radius ); this.m_Body = world.CreateBody(bodyDef); this.m_Body.CreateFixture(fixDef); m_spriteCircle = new My_Sprite(); this.Init(); } Circle.prototype.Init = function () { m_spriteCircle.constructor("images/circle.png", new Vector2D(80, 80), 1); m_spriteCircle.m_CurFrame = 0; } Circle.prototype.Draw = function (context) { m_spriteCircle.Draw(context); } and I draw it : var m_Circle = new Circle(); m_Circle.Draw(context);

    Read the article

  • Error in destroying object in Box2D/LibGDX

    - by Crypted
    I'm trying to delete an object when a collision happens. I have put the following code in the render method of the object so it would be outside of the physics calculations. public void render(SpriteBatch spriteBatch) { // some other code... body.setActive(false); body.getWorld().destroyBody(body); But I'm getting an run-time error which crashes the JVM and shows, AL lib: alc_cleanup: 1 device not closed Assertion failed! Program: C:\Program Files\Java\jre6\bin\javaw.exe File: /var/lib/hudson/jobs/libgdx-git/workspace/gdx/jni/Box2D/Dynamics/b2World.cpp, Line 133 Expression: m_bodyCount 0 Can anyone help me here?

    Read the article

  • coloring box2d body in LibGDX

    - by ved
    I want to color polygon of box2d in LibGDX. Found below useful class for that. http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/glutils/ShapeRenderer.html But, it is not coloring the body instead making colored shapes. I want colored bodies having all the property like gravity, restitution etc. In brief, I want to make colored ball and surface.And i don't want to attach sprite on bodies. Want just fill color in bodies. Need some guidance????

    Read the article

  • Making body (box2d) a sprite (andengine) in Android

    - by Kadir
    I can't make body (box2d) a sprite (andengine) and at the same time apply MoveModifier to sprite which is body. If i can make just body, it works namely the sprites can collide. If I apply just MoveModifier to sprites, the sprites can move where i want. But I want to make body (they can collide) and apply MoveModifier (they can move where I want) at the same time. How can i do it? This my code just run MoveModifier not as body at the same time. circles[i] = new Sprite(startX, startY, textRegCircle[i]); body[i] = PhysicsFactory.createCircleBody(physicsWorld, circles[i], BodyType.DynamicBody, FIXTURE_DEF); physicsWorld.registerPhysicsConnector(new PhysicsConnector(circles[i], body[i], true, true)); circles[i].registerEntityModifier( (IEntityModifier) new SequenceEntityModifier ( new MoveModifier(10.0f, circles[i].getX(), circles[i].getX(), circles[i].getY(),CAMERA_HEIGHT+64.0f))); scene.getLastChild().attachChild(circles[i]); scene.registerUpdateHandler(physicsWorld);

    Read the article

  • Box2D Platform body not moving player body along with it

    - by onedayitwillmake
    I am creating a game using Box2D (Javascript implementation) - and I added the ability to have a static platform, that is moved along an axis as a function of a sine. My problem is when the player lands on the platform, as the platform moves along the X axis - the player is not moved along with it, as you visually would expect. The player can land on the object, and if it hits the side of the object, it does colide with it and is pushed. This image might explain better than I did: After jumping on to the red platform the player character will fall off as the platform moves to the right UPDATE: Here is a live demo showing the problem: http://onedayitwillmake.com/ChuClone/slideexample.php

    Read the article

  • Physics in carrom like game using cocos2d + Box2D

    - by Raj
    I am working on carrom like game using cocos2d + Box2D. I set world gravity(0,0), want gravity in z-axis. I set following values for coin and striker body: Coin body (circle with radius - 15/PTM_RATIO): density = 20.0f; friction = 0.4f; restitution = 0.6f; Striker body (circle with radius - 15/PTM_RATIO): density = 25.0f; friction = 0.6f; restitution = 0.3f; Output is not smooth. When I apply ApplyLinearImpulse(force,position) the coin movement looks like floating in the air - takes too much time to stop. What values for coin and striker make it look like real carrom?

    Read the article

  • Box2D physics editor for complex bodies

    - by Paul Manta
    Is there any editor out there that would allow me to define complex entities, with joins connecting their multiple bodies, instead of regular single body entities? For example, an editor that would allow me to 'define' a car as having a main body with two circles as wheels, connected through joints. Clarification: I realize I haven't been clear enough about what I need. I'd like to make my engine data-driven, so all entities (and therefore their Box2D bodies) should be defined externally, not in code. I'm looking for a program like Code 'N' Web's PhysicsEditor, except that one only handles single body entities, no joints or anything like that. Like PhysicsEditor, the program should be configurable so that I can save the data in whatever format I want to. Does anyone know of any such software?

    Read the article

  • Scrolling Box2D DebugDraw

    - by onedayitwillmake
    I'm developing a game using Box2D (javascript implementation - Box2DWeb), and I would like to know how I can pan the debug draw. I know the usual answer is - don't use debug draw, it's just for debugging. I'm not, however not all my objects are on the same screen, and i'd like to see where they are in the physics representation. How can I pan the debug drawing? As you can see the debug draw stuff, is show on the top left, but it only shows a small part of the world. Here is an example of what I mean: http://onedayitwillmake.com/ChuClone/ The game is open source, If you'd like to poke through and note something that perhaps i'm doing something that is obviously wrong: https://github.com/onedayitwillmake/ChuClone Here's my hacky way that I'm using now to scroll the b2DebugDraw view, in which I added a property offsetX and offsetY into b2DebugDraw

    Read the article

  • Making body(box2d) a spite(andengine) in android

    - by Kadir
    I can't make body(box2d) a spite(andengine) and at the same time i wanna apply MoveModifier to sprite which is body.if i can make just body,it works namely the srites can collide.if i can apply just MoveModifier to sprites,the sprites can move where i want.but i wanna make body(they can collide) and apply MoveModifier(they can move where i want) at the same time.How can i do? this my code just run MoveModifier not as body at the same time. circles[i] = new Sprite(startX, startY, textRegCircle[i]); body[i] = PhysicsFactory.createCircleBody(physicsWorld, circles[i], BodyType.DynamicBody, FIXTURE_DEF); physicsWorld.registerPhysicsConnector(new PhysicsConnector(circles[i], body[i], true, true)); circles[i].registerEntityModifier( (IEntityModifier) new SequenceEntityModifier ( new MoveModifier(10.0f, circles[i].getX(), circles[i].getX(), circles[i].getY(),CAMERA_HEIGHT+64.0f))); scene.getLastChild().attachChild(circles[i]); scene.registerUpdateHandler(physicsWorld);

    Read the article

  • Implementing top view physics using box2D

    - by humbleBee
    How can top view physics games be done in box2D? One idea I have is to set the linear velocity of an object manually or to alter the linear and angular damping as my object moves over different surfaces. For example if my object is over a wet surface it'll have less linear damping and if it is over rough surface it'll have more damping. And to see if my object has fallen over an edge I'll try to use an AABB and check if its still inside or manually see if object.x > boundary.x etc. Is there any better way?

    Read the article

  • Scrolling Box2D DebugDraw

    - by onedayitwillmake
    I'm developing a game using Box2D (javascript implementation - Box2DWeb), and I would like to know how I can pan the debug draw. I know the usual answer is - don't use debug draw, it's just for debugging. I'm not, however not all my objects are on the same screen, and i'd like to see where they are in the physics representation. How can I pan the debug drawing? As you can see the debug draw stuff, is show on the top left, but it only shows a small part of the world. Here is an example of what I mean: http://onedayitwillmake.com/ChuClone/ The game is open source, If you'd like to poke through and note something that perhaps i'm doing something that is obviously wrong: https://github.com/onedayitwillmake/ChuClone

    Read the article

  • Using box2d DrawDebugData with multi layer scene ?

    - by Mr.Gando
    In my Game, a Scene is composed by several layers. Each layer has different camera transformations. This way I can have a layer at z=3 (GUI), z=2 (Monsters), z=1 (scrolling background), and this 3 layers compose my whole Scene. My render loop looks something like: renderLayer() applyTransformations() renderVisibleEntities() renderChildLayers() end If I call DrawDebugData() in the render loop, the whole b2world debug data will be rendered once for each layer in my scene, this generates a mess, because the "debug boxes" get duplicated, some of them get the camera transformations applied and some of them don't, etc. What I would like to do, would be to make DrawDebugData to draw only certain debug boxes. In that way, I could call something like b2world->DrawDebugDataForLayer(int layer_id) and call that on each layer like : renderLayer() applyTransformations() renderVisibleEntities() //Only render my corresponding layer debug data b2world->DrawDebugDataForLayer(layer_id) renderChildLayers() end Is there a way to subclass b2World so I could add this functionality ( specific to my game ) ? If not, what would be the best way to achieve this (Cocos2d uses a similar scene graph approach and box2d, but I'm not sure if debugDraw works in Cocos2d... ) Thanks

    Read the article

  • Simple 2D Flight Physics with Box2D

    - by MarkPowell
    I'm trying to build a simple side scroller with an airplane being the player. As such, I want to build simple flight controls with simple but realistic-feeling physics. I'm making use of cocos2D and Box2D. I have a basic system working, but just can't get the physics feeling correct. I am applying force to the plane (which is a b2CircleShape) based on the user's input. So, basically, if the user pushes up, body_->ApplyForce(b2Vec2(10,30), body_->GetPosition()) is called. Similarly, for down -30 is used. This works and the plane flys along with up/down causing it to dive or climb. But it just doesn't feel right. There is no slowdown on climbs, nor speed up during dives. My simple solution is far to simple. How can I get a better feel for a plane climbing/diving? Thanks!

    Read the article

  • Box2D random crash when adding joints

    - by user46624
    I'm currently working on a project which uses Box2D, when the player uses a certain key it should anchor to the ground. For that I use a weld joint, but when I add the joint the game will sometimes crash, it has a 1/10 change to crash. The error I recieve: Showing the controller Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 11 at org.jbox2d.dynamics.Island.add(Island.java:577) at org.jbox2d.dynamics.World.solve(World.java:1073) at org.jbox2d.dynamics.World.step(World.java:598) The code for adding the joints: WeldJointDef def = new WeldJointDef(); def.initialize(body, anchoredObject.body, body.getWorldCenter()); weldJoint = (WeldJoint) world.createJoint(def); I still get the error if I synchronize it

    Read the article

  • Specifying force and angle in ApplyImpulse in box2d

    - by Deepak Mahalingam
    I need to apply an impulse on a object with a particular force and at a particular angle in Box2d. If I am right the syntax would be the following: body.GetBody().ApplyImpulse(new b2Vec2(direction, power),body.GetBody().GetWorldCenter()); The problem is my direction is in angles. I found a discussion where it was said that the way we can convert an angle into a vector would be as: new b2Vec2(Math.cos(angle*Math.PI/180),Math.sin(angle*Math.PI/180)); Now I am not sure how to combine these two. In other words, if I wish to apply a force of 30 units at an angle of 30 degrees at the center of the object, how should I do it?

    Read the article

  • What's the best way to handle slopes for a platfomer game using Box2D

    - by songokuhd
    I would like to know if there is any known solution for handling the player's movement on slopes using Box2D engine. I tried to do it using a circle as the player. Everything was fine until I tried to walk on slopes, the main problem is that due to gravity, the circle does not stop on the slope. Please if somebody has tried this before I'll appreciate it. If you have a better solution without the physics engine would be fine for me too. Thank you.

    Read the article

  • box2d tween what am I missing

    - by philipp
    I have a Box2D project and I want to tween an kinematic body from position A, to position B. The tween function, got it from this blog: function easeInOut(t , b, c, d ){ if ( ( t /= d / 2 ) < 1){ return c/2 * t * t * t * t + b; } return -c/2 * ( (t -= 2 ) * t * t * t - 2 ) + b; } where t is the current value, b the start, c the end and d the total amount of frames (in my case). I am using the method introduced by this lesson of todd's b2d tutorials to move the body by setting its linear Velocity so here is relevant update code of the sprite: if( moveData.current == moveData.total ){ this._body.SetLinearVelocity( new b2Vec2() ); return; } var t = easeNone( moveData.current, 0, 1, moveData.total ); var step = moveData.length / moveData.total * t; var dir = moveData.direction.Copy(); //this is the line that I think might be corrected dir.Multiply( t * moveData.length * fps /moveData.total ) ; var bodyPosition = this._body.GetWorldCenter(); var idealPosition = bodyPosition.Copy(); idealPosition.Add( dir ); idealPosition.Subtract( bodyPosition.Copy() ); moveData.current++; this._body.SetLinearVelocity( idealPosition ); moveData is an Object that holds the global values of the tween, namely: current frame (int), total frames (int), the length of the total distance to travel (float) the direction vector (targetposition - bodyposition) (b2Vec2) and the start of the tween (bodyposition) (b2Vec2) Goal is to tween the body based on a fixed amount of frames: in moveData.total frames. The value of t is always between 0 and 1 and the only thing that is not working correctly is the resulting distance the body travels. I need to calculate the multiplier for the direction vector. What am I missing to make it work?? Greetings philipp

    Read the article

  • strange behavior in Box2D+LibGDX when applying impulse

    - by Z0lenDer
    I have been playing around with Box2D and LibGDX and have been using a sample code from DecisionTreeGames as the testing ground. Now I have a screen with four walls and a rectangle shape, lets call it a brick. When I use applyLinearImpulse to the brick, it starts bouncing right and left without any pattern and won't stop! I tried adding friction and increasing the density, but the behavior still remains the same. Here are some of the code that might be useful: method for applying the impulse: center = brick.getWorldCenter(); brick.applyLinearImpulse(20, 0, center.x, center.y); Defining the brick: brick_bodyDef.type = BodyType.DynamicBody; brick_bodyDef.position.set(pos); // brick is initially on the ground brick_bodyDef.angle = 0; brick_body = world.createBody(brick_bodyDef); brick_body.setBullet(true); brick_bodyShape.setAsBox(w,h); brick_fixtureDef.density = 0.9f; brick_fixtureDef.restitution = 1; brick_fixtureDef.shape = brick_bodyShape; brick_fixtureDef.friction=1; brick_body.createFixture(fixtureDef); Walls are defined the same only their bullet value is set to false I would really appreciate it if you could help me have a change this code to have a realistic behavior (i.e. when I apply impulse to the brick it should trip a few times and then stop completely).

    Read the article

  • AndEngine Box2d game

    - by OneMoreVladimir
    I'm developing a 2d survival shooter using Box2d extension and I've got some questions: I have two AnalogOnScreenControls. Their listeners modify both sprites and bodies. I receive TouchEventPool was exhausted and as their number grows the game crashes accidently. I've tried to put the modification of the bodies and sprites on the UpdateThread but that does not solve the problem. What could be the cause? I have a class that at the beginnig of the game loads all the textures. After I relaunch the game activity several times I receive Unable to find Phys Addr for and "green color" interface. But that doesn't happen if I clear the memory manually through the Task Manager before relaunch What could be the cause? I unload my atlas at the end of the game. The game sometimes crashes at start with NullPointerException in onResumeGame. The solution suggested is to set android:configChanges="orientation|screenSize" but my device is API 10 so it doesn't have screenSize property and orientation only does not seem to help, because the game starts in portrait mode at times (though landscape is set in the code)

    Read the article

  • Create indefinitely oscillating pendulum in Farseer Physics 3.3.1/Box2d

    - by GONeale
    I am new to Farseer Physics and using version 3.3.1. I am after some help and would even be happy to receive Box2d answers just to ensure I get a response as I should then be able to convert it! -- Thanks ...After a lot of tinkering around I have managed to produce a thin vertical rectangle shape on the screen and I wish this to swing back and forth pinned at the top up to an angle I set (90 degrees would be fine for this sample). When it is approaching the top I wish it to slow down, then fall back the way it just came, increase speed then obviously slow to a stop at the top again. Almost how a swinging pirate ship would work at a theme park. This is the code I have so far which swings the shape, but it is seeming to lose speed on each swing eventually grinding to a halt: float playerWidth = ConvertUnits.ToSimUnits(5), playerHeight = ConvertUnits.ToSimUnits(68); playerPosition = ConvertUnits.ToSimUnits(-350, 0); playerBody = BodyFactory.CreateRectangle(World, playerWidth, playerHeight, 2f, playerPosition); playerBody.BodyType = BodyType.Dynamic; // create player sprite based on player body _rectangleSprite = new Sprite(ScreenManager.Assets.TextureFromShape(playerBody.FixtureList[0].Shape, MaterialType.Player, Color.Orange, 1f)); // Create swinging joint var joint = JointFactory.CreateFixedRevoluteJoint(World, playerBody, ConvertUnits.ToSimUnits(0, -34), playerBody.Position); If somebody could also provide the command I would need to pause the shape on a mouse click or keyboard command at it's current angle and then continue when I let go of the mouse click that would be super fantastic! (I actually posted this on StackOverflow as well before I realised there was a dedicated game development forum) Cheers

    Read the article

  • What could cause a sudden stop in Box2D?

    - by alexanderpine
    I'm using Box2d for a game, and I have a bug that's driving me nuts. I've simplified the situation down to a square player sliding back and forth frictionlessly on top of a floor composed of a series of square tiles, driven by the left and right keys (which apply a horizontal force). Works great, sliding back and forth across the whole floor. Except... Every once in a while, the player will suddenly stick at the edge of one of the tiles as if it is hitting a (nonexistent) wall. Further pushes in the same direction it was traveling will fail, but as soon as I push backwards once in the opposite direction, I can push forwards past the sticking point again. The sticking point seems to be random, except for being on the edge of a tile. Happens while going left or right. For debugging purposes, I keep the Positions/velocity values for the previous two update ticks and print them out when this stop occurs. As an example, here you see the player moving right, decelerating slightly; pos2 should be about 8.7, but it stops dead instead. tick0: pos= 8.4636 vel= 7.1875 tick1: pos= 8.5816 vel= 7.0833 tick2: pos= 8.5816 vel= 0.0000 So, as the player is 0.8 and the tiles 1.0 wide, the player is stopping just as it is about to cross onto the next tile (8.5816 + 0.8/2 = 8.9816). In fact, I get a collision message (which I ignore except noting that it happened). It only seems to happen at x.5816 (or -x.4184) while moving right, and x.4167 (or -x.5833) while moving left I said that it's like hitting a wall, but in fact, when it hits a wall, the numbers look more like: tick0: pos0= 12.4131 vel2= 8.4375 tick1: pos1= 12.5555 vel1= 8.5417 tick2: pos2= 12.5850 vel0= 0.0000 so it moves further right on the last tick, which puts it in contact with the wall. Anyone seen anything like this. Any suggestion on how I could be causing this behavior.

    Read the article

  • Transforms in Box2D

    - by user1264811
    I'm attempting to implement a camera in my game. I had it working for regular objects, but I began using Box2D and obviously things changed a bit. I have a Body object that I want to draw at the center of the screen. Basically what I'm doing is subtracting the viewportX and viewportY to the Body. I use this code that currently is not working as it should: public void paint(Graphics2D g, int viewportX, int viewportY) { Transform xf = new Transform(); // m_body is the Body object xf.set(m_body.getTransform()); // Here what I attemp to do is take the transform and alter it // by the viewportX and Y, which is something like **-240, -150**. // Why is it negative? Because an object has coordinates 500, 300 would be displayed // at 160, 150 when the subtraction is done. // With the DrawUtils.toScale(), it's just how I convert the units from JBox2D units // to my units. Vec2 v = Transform.mulTrans(xf, new Vec2(DrawUtils.toScale(-viewportX), DrawUtils.toScale(-viewportY))); // Set the new transform to the new vector. Keep the old angle. xf.set(v, xf.q.getAngle()); g.setColor(Color.white); // I know for a fact that the following method works 100%. It correctly displays // my object, just that it doesn't follow it. for (Fixture f = m_body.getFixtureList(); f != null; f = f.getNext()) DrawUtils.drawShape(f, xf); } Hopefully I didn't over comment this and you understand my problem. I don't want to alter the actual physics position of the object, I just want to display it in the center.

    Read the article

  • What causes Box2D revolute joints to separate?

    - by nbolton
    I have created a rag doll using dynamic bodies (rectangles) and simple revolute joints (with lower and upper angles). When my rag doll hits the ground (which is a static body) the bodies seem to fidget and the joints separate. It looks like the bodies are sticking to the ground, and the momentum of the rag doll pulls the joint apart (see screenshot below). I'm not sure if it's related, but I'm using the Badlogic GDX Java wrapper for Box2D. Here's some snippets of what I think is the most relevant code: private RevoluteJoint joinBodyParts( Body a, Body b, Vector2 anchor, float lowerAngle, float upperAngle) { RevoluteJointDef jointDef = new RevoluteJointDef(); jointDef.initialize(a, b, a.getWorldPoint(anchor)); jointDef.enableLimit = true; jointDef.lowerAngle = lowerAngle; jointDef.upperAngle = upperAngle; return (RevoluteJoint)world.createJoint(jointDef); } private Body createRectangleBodyPart( float x, float y, float width, float height) { PolygonShape shape = new PolygonShape(); shape.setAsBox(width, height); BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.DynamicBody; bodyDef.position.y = y; bodyDef.position.x = x; Body body = world.createBody(bodyDef); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = shape; fixtureDef.density = 10; fixtureDef.filter.groupIndex = -1; fixtureDef.filter.categoryBits = FILTER_BOY; fixtureDef.filter.maskBits = FILTER_STUFF | FILTER_WALL; body.createFixture(fixtureDef); shape.dispose(); return body; } I've skipped the method for creating the head, as it's pretty much the same as the rectangle method (just using a cricle shape). Those methods are used like so: torso = createRectangleBodyPart(x, y + 5, 0.25f, 1.5f); Body head = createRoundBodyPart(x, y + 7.4f, 1); Body leftLegTop = createRectangleBodyPart(x, y + 2.7f, 0.25f, 1); Body rightLegTop = createRectangleBodyPart(x, y + 2.7f, 0.25f, 1); Body leftLegBottom = createRectangleBodyPart(x, y + 1, 0.25f, 1); Body rightLegBottom = createRectangleBodyPart(x, y + 1, 0.25f, 1); Body leftArm = createRectangleBodyPart(x, y + 5, 0.25f, 1.2f); Body rightArm = createRectangleBodyPart(x, y + 5, 0.25f, 1.2f); joinBodyParts(torso, head, new Vector2(0, 1.6f), headAngle); leftLegTopJoint = joinBodyParts(torso, leftLegTop, new Vector2(0, -1.2f), 0.1f, legAngle); rightLegTopJoint = joinBodyParts(torso, rightLegTop, new Vector2(0, -1.2f), 0.1f, legAngle); leftLegBottomJoint = joinBodyParts(leftLegTop, leftLegBottom, new Vector2(0, -1), -legAngle * 1.5f, 0); rightLegBottomJoint = joinBodyParts(rightLegTop, rightLegBottom, new Vector2(0, -1), -legAngle * 1.5f, 0); leftArmJoint = joinBodyParts(torso, leftArm, new Vector2(0, 1), -armAngle * 0.7f, armAngle); rightArmJoint = joinBodyParts(torso, rightArm, new Vector2(0, 1), -armAngle * 0.7f, armAngle);

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10  | Next Page >