box2d

How to create whirlpool/vortex effect?

谁都会走 提交于 2019-12-02 07:49:29
问题 Im trying to make a Vortex effect on a Circle Body that is a Sensor. I've been looking for this and all examples i look for are in C++ or Objective C and i dont seem to translate them well. when my objects collition, it calls beginContact(..) and it sets a flag so that i can call bodyToUpdate.applyForce(...); public void beginContact(Contact contact) { setColliding(true); } //updating collition every frame public void act(){ if (colliding) { ball.getBody().applyForce(....); } how to calculate

How to create whirlpool/vortex effect?

时间秒杀一切 提交于 2019-12-02 07:09:33
Im trying to make a Vortex effect on a Circle Body that is a Sensor. I've been looking for this and all examples i look for are in C++ or Objective C and i dont seem to translate them well. when my objects collition, it calls beginContact(..) and it sets a flag so that i can call bodyToUpdate.applyForce(...); public void beginContact(Contact contact) { setColliding(true); } //updating collition every frame public void act(){ if (colliding) { ball.getBody().applyForce(....); } how to calculate the amount of force to apply every frame to make it a vortex? Edit: so i now have the object going

Fixing two box2D bodies together securely

我的未来我决定 提交于 2019-12-02 06:25:23
I am trying to join two box2d bodies together that are separated over a fixed distance. Both bodies cannot rotate themselves, and the join should have to rotation either. The gap between the bodies needs to allow other bodies to pass through. I currently have a b2revoluteJoint setup like so: b2RevoluteJointDef rjd; rjd.lowerAngle = 0.0f; rjd.upperAngle = 0.0f; rjd.Initialize(body2, body1, body2->GetPosition()); rjd.collideConnected = false; world->CreateJoint(&rjd); However the joint is not completely rigid and the bodies tend to move around a fair bit relative to each other. Is there a better

Rotating multiple sprites as one ( around same origin )

↘锁芯ラ 提交于 2019-12-02 04:04:43
问题 I have array of sprites forming T shape, and I want to ratate them around the same origin, in my case box2D body origin, like this: my shape is defined in matrix like this: int array[][]= {{0,1,1,1,0}, {0,0,1,0,0}, {0,0,1,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}; this is how I create the body: public void setBody(int[][] blocks){ BodyDef def = new BodyDef(); def.type = BodyType.DynamicBody; def.position.set(new Vector2(0 * WORLD_TO_BOX, 0 * WORLD_TO_BOX)); Body body = world.createBody(def); body

not proper collision in box2d

给你一囗甜甜゛ 提交于 2019-12-02 02:29:10
问题 I am developing a game in which the user have to hit a high speed ball. To hit the ball I have joined a rectangular body with the actor using revolute joint and enabled its motor, to rotate it with a specified speed(motor speed). Now everything is perfect but sometime when ball`s velocity is high , it is bypassing the rectagular body. Using collision listner i found that collision is happening but ball is not getting reflected after collision. As this is happening only when ball is on a high

Rotating multiple sprites as one ( around same origin )

泄露秘密 提交于 2019-12-02 01:21:37
I have array of sprites forming T shape, and I want to ratate them around the same origin, in my case box2D body origin, like this: my shape is defined in matrix like this: int array[][]= {{0,1,1,1,0}, {0,0,1,0,0}, {0,0,1,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}; this is how I create the body: public void setBody(int[][] blocks){ BodyDef def = new BodyDef(); def.type = BodyType.DynamicBody; def.position.set(new Vector2(0 * WORLD_TO_BOX, 0 * WORLD_TO_BOX)); Body body = world.createBody(def); body.setTransform(130*WORLD_TO_BOX, 200*WORLD_TO_BOX, -90*MathUtils.degreesToRadians); for (int x = 0; x < 5; x++

not proper collision in box2d

流过昼夜 提交于 2019-12-02 01:15:05
I am developing a game in which the user have to hit a high speed ball. To hit the ball I have joined a rectangular body with the actor using revolute joint and enabled its motor, to rotate it with a specified speed(motor speed). Now everything is perfect but sometime when ball`s velocity is high , it is bypassing the rectagular body. Using collision listner i found that collision is happening but ball is not getting reflected after collision. As this is happening only when ball is on a high speed, is it bcoz of density of bodies that are colliding . Or its the motor of revolute joint that is

Create a random, sine graph like landscape sprite

坚强是说给别人听的谎言 提交于 2019-12-01 18:04:30
问题 Lets say I have this sprite: And I created a random landscape during runtime: And then, I want to tile the area below the line with the sprite: This is the game ground, therefore it should also be a physics object (In Box2D) . Here, he given a sample of how to make this a physics body. So, how do I do the graphics part in code? EDIT: Looking in the AndEngine examples, file RepeatingSpriteBackgroundExample.java, it's not exactly what I need but should I stick to this idea and change the

Rendering box2d in libgdx

荒凉一梦 提交于 2019-12-01 14:16:27
I have a game world of size 800x480 using a FitViewport and was initally rendering box2d bodies + fixtures using pixels so all the physics appeared floating and slow. Looking at the documentation I realised box2d uses metrics units so I went through and converted the box2d positions and sizes by a factor of 32 so I end up with a box2d world of 25x15 metres. The issue I'm having is that now box2d objects are rendered incredibly small. How can I scale them back so they appear regular size on screen? You need to use conversions factor between world and box2. In your create() you'll have : private

box2d contact listener fixtures order

。_饼干妹妹 提交于 2019-12-01 14:02:57
I am trying to understand how does it work. In my game I use box2d physics, to handle contacts I use contact listener, example: ContactListener contactListener = new ContactListener() { @Override public void beginContact(Contact contact) { final Fixture x1 = contact.getFixtureA(); final Fixture x2 = contact.getFixtureB(); if (x1.getBody().getUserData() != null && x2.getBody().getUserData() != null) { if (x1.getBody().getUserData().equals("player")) { player.increaseFootContacts(); } } } And here`s question, is there any order in those fixtures? (x1 or x2) after 2 test, I found out that in this