box2d

How to create a sine wave in processing?

我只是一个虾纸丫 提交于 2019-12-12 01:52:51
问题 I would like to create a sine wave using vectors (as I am using box2d ). So far I have (in void draw() ) Vec2 mov2 = new Vec2(sin(angle)*scalar,0); for (int j = 0; j <= 10; j++) { bridge.particles.get(j).body.setLinearVelocity(mov2); } where bridge is a chain of particles . However, this makes all the particles move back and forth at the same time whereas I would like to move like a sine wave so that each particle moves just slightly after the previous one. 回答1: You need to add some sort of

When creating a joint during runtime, object teleports

蹲街弑〆低调 提交于 2019-12-12 01:06:54
问题 I have two objects and when the distance between them is less than 10, I create a joint: var joint_def = new box2d.b2RevoluteJointDef(); joint_def.bodyA = body1; joint_def.bodyB = body2; joint_def.localAnchorA = new box2d.b2Vec2(0, 0); joint_def.localAnchorB = new box2d.b2Vec2(0, 0); world.CreateJoint(joint_def); The problem is, however, that one object teleports/jumps on top of the other. The intended behavior would be that one object slowly moves on top of the other. Any idea? Thanks. 回答1:

An odd, cryptic error from libgdx's version of box2d involving a mousejoint

对着背影说爱祢 提交于 2019-12-11 21:15:06
问题 Code There is my code for my Screen object. The garble of arrays and Vector2 s at the bottom is just a long list of models for the cats. My goal is to make a port of http://catsinspace.co.nf, my website, to learn how to use libgdx and its box2d port. I am trying to get the mousejoint working, but I apparently don't understand how a groundBody is supposed to work, despite my hours of googling. Here is my strange, cryptic error that I have tried googling fruitlessly: AL lib: alc_cleanup: 1

Calculating distance travelled by a b2body before it stops in Box2D

自作多情 提交于 2019-12-11 20:47:22
问题 I have a zero gravity world. I have a catapult using which a box2d body is shot into space. I calculate a certain force and apply it to the body along with a certain damping factor. My code hence looks like this: _body->ApplyForce(force, b2Vec2(position.x / PTM_RATIO, position.y / PTM_RATIO)); float damping = 1.5f; _body->SetLinearDamping(damping); I want to calculate the distance it travels before it ultimately stops. What is the correct way to calculate it? I am calculating it using -

b2Body Animation?

若如初见. 提交于 2019-12-11 18:17:11
问题 I am using Box2D with Cocos2D in my game. I am aware that Cocos2D has a animation API named CCMoveTo. I want to do the same thing in Box2D with b2Bodies. I want to be able to set a destination point and a animation time from the point it is initially at. Does anyone know if this is possible or not? I am just trying to keep this as simple as possible. I am open to ideas and suggestions! Thanks! Edit1 : Ok so I want to make my b2Bodys following my CCSprite permanently. There is a problem with

How to implement horizontal and vertical scroll in box2d world properly?

谁说我不能喝 提交于 2019-12-11 18:08:03
问题 I have implemented horizontal scroll, but vertical scroll making trouble, and the trouble is difficult to explain. So I can scroll scene vertically, and horizontally, if that is been done from the scene's origin, i.e ccp(0,0). But when Scrolling towards X have been done, and been paused in the middle, then if i scroll it vertically, it actually scroll diagonally, back to origin(x), and new position of y. I know it's complicated to understand, but how can it be achieved to scroll it vertically

Need to know when collision is begin and end box2d

懵懂的女人 提交于 2019-12-11 17:08:51
问题 public class Contact implements ContactListener { @Override public void beginContact(Contact contact) { Fixture fa = contact.getFixtureA(); Fixture fb = contact.getFixtureB(); if (fa.getFilterData().categoryBits==16){ ((Gamescreen)fa.getUserData()).starttouch(fa,fb); } @Override public void endContact(Contact contact) { Fixture fa = contact.getFixtureA(); Fixture fb = contact.getFixtureB(); if (fa.getFilterData().categoryBits==16) { ((Gamescreen)fa.getUserData()).endtouch(); } This code works

How to set fixed drawing speed and world steps in Box2D and SFML?

岁酱吖の 提交于 2019-12-11 16:59:51
问题 There is a simple project, Box2D is engaged in physics, SFML draws. On different machines with different performance speed of the program varies. How to set a fixed speed? So that would on a powerful, average and weak computer the speed of the program (movement of objects) were the same? We need to make Box2D work on different computers at the same speed. It also gives coordinates, and SFML draws a square at the given coordinates. How to solve this problem? 回答1: Constant Frame Rate is what

How to make a box2d Body object collidable with the other Body

不想你离开。 提交于 2019-12-11 16:17:18
问题 How to make a com.badlogic.gdx.physics.box2d.Body object collidable with the other Body in Scene2d(libgdx) while working with the Box2d extension, when both the body types are Dynamic.? 回答1: if I understand correctly, your question can this helps where to create the Body2, add this example in your code: .// YourBody2 = YourWorld.createBody(bd); YourBody2.createFixture(fixDef).setUserData("YourBody2"); where to create the Body1, add this example in your code: .// YourBody1 = YourWorld

Move my body to a point

旧城冷巷雨未停 提交于 2019-12-11 14:32:56
问题 I am using box 2d. I just want to move my body to the point. What is the best way to do this? 回答1: When you say you just want to move the body, do you mean you want to apply a force to get the body to a point? There's a joint designed for mouse movement, and it might work well in your case if you want to drag bodies around on an iPhone. It's called the Mouse Joint, and it's under 8.10 on these box2d docs. If you want a body that doesn't respond to things hitting it, but pushes things around