box2d

How to detect collision but do not collide in box2d?

血红的双手。 提交于 2019-11-28 09:13:09
How to detect if body collides other body but do not react on this collision. By default i - detect collision and bodies collide. If i set fixtureDef filter - bodies do not collide but i can not detect collision. Help please! If the fixture never needs to collide with anything you could make it a sensor. If you need it to collide with some things but not others you could do contact->SetEnabled(false) in the PreSolve of the collision listener, depending on what it collided with. What you want here is a sensor fixture on a body. From the box2d manual: Sometimes game logic needs to know when two

Box2d multiple fixtures and positioning

佐手、 提交于 2019-11-28 07:36:30
I'm attempting to create a "U" shape in Box2d (in Cocos2d) by joining 3 rectangles like so: |_| It sounds like joints are not the correct solution here since I don't want any movement so I have created a main body which is the middle bit and 2 fixtures for the sides. I've added the two sides to the middle bit like this: mainBody->CreateFixture(&leftFixtureDef); mainBody->CreateFixture(&rightFixtureDef); This works, however both side fixtures get added to the center of the mainBody. I can't seem to work out how to position the fixtures relative to the main body. Attaching a sprite/node to the

Box2d: Maximum possible linear velocity?

筅森魡賤 提交于 2019-11-28 00:19:33
问题 I think I've configured Box2d to have some sort of maximum velocity for any body, but I'm not sure. I apply an impulse like (100000000, 100000000) , and the body moves just as fast as (100, 100) - which is not that fast at all. I'm using the Box2d XNA C# port. My game is a top-down 2d. Here is some code that may be relevant: private readonly Vector2 GRAVITY = new Vector2(0, 0); public void initializePhysics(ContactReporter contactReporter) { world = new World(GRAVITY, true); IContactListener

Why use Float.floatToIntBits() in Java float comparisons?

半城伤御伤魂 提交于 2019-11-27 15:48:01
问题 In JBox2d, there exists the following code for Vec2.equals() : @Override public boolean equals(Object obj) { //automatically generated by Eclipse if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Vec2 other = (Vec2) obj; if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x)) return false; if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y)) return false; return true; } I am wondering what purpose the float<->int bit

Move body to a specific position - Box2D

情到浓时终转凉″ 提交于 2019-11-27 10:34:34
问题 I have a b2Body which I would like to move at a certain target position. I don't want to use the SetPosition function. How can I achieve this using : Changing linear velocities. Using mouseJoint. (The target position is fixed. Mouse is NOT involved.) I'm using Box2DAS3 2.1a. Help in any other language would also be appreciated. 回答1: The simplest way is actually to use SetPosition / SetTransform(position,angle) . For example: body->SetTransform(b2Vec2(0,0),body->GetAngle()) Obviously, the

Simple gun in cocos2d+box2d game

a 夏天 提交于 2019-11-27 09:10:44
I'm newbie in box2d. Can you help me? I want to make gun (touch, move, stopped, ball flew). I make detection and rotation of gun, but I can't make popping of ball. How can I count velocity, which I need to set to the ball? Thank you very much The easiest way is to look at the direction the gun is pointing when you define the body, and use GetWorldVector to see how it has changed. For example if the gun is pointing directly upwards when you create the body, this would be the direction (0,1). Then you can use GetWorldVector at any time to get the current direction of that vector in world

SpriteKit physics in Swift - Ball slides against wall instead of reflecting

我的未来我决定 提交于 2019-11-27 08:24:17
I have been creating my own very simple test game based on Breakout while learning SpriteKit (using iOS Games by Tutorials by Ray Wenderlich et al.) to see if I can apply concepts that I have learned. I have decided to simplify my code by using an .sks file to create the sprite nodes and replacing my manual bounds checking and collision with physics bodies. However, my ball keeps running parallel to walls/other rectangles (as in, simply sliding up and down them) any time it collides with them at a steep angle. Here is the relevant code--I have moved the physics body properties into code to

How do I apply a force to a body in the direction it is traveling (Box2D)?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 03:35:31
问题 I'm using AndEngine/Box2d to develop a game. I have a ball that bounces around the screen. I've successfully made it ignore gravity by applying an opposite force, but it has a tenancy to slow down after the initial impulse, even with the elasticity set to 1. Essentially I want to: if(speed < a number ) apply force or impulse (which is better?) in direction of motion How might I do this? 回答1: Well unfortunately, the ball is interacting with other objects so setting velocity did not work, but I

Libgdx light without box2d

蹲街弑〆低调 提交于 2019-11-27 02:53:03
问题 I just started creating a game using libgdx. It is a top down 2d shooter using scene2d ui. Now i thought, that i could add darkness and light to some levels, but i don't want to rewrite everything using box2d. I don't need realistic shadows just some kind of ambient light and a lightcircle arround my character, which is not affected by walls and other obstacles arround him. So i wanted to know if there is any kind of lightsystem in libgdx? Or can i use box2dlights without using box2d bodies

How to detect collision but do not collide in box2d?

本小妞迷上赌 提交于 2019-11-27 02:23:16
问题 How to detect if body collides other body but do not react on this collision. By default i - detect collision and bodies collide. If i set fixtureDef filter - bodies do not collide but i can not detect collision. Help please! 回答1: If the fixture never needs to collide with anything you could make it a sensor. If you need it to collide with some things but not others you could do contact->SetEnabled(false) in the PreSolve of the collision listener, depending on what it collided with. 回答2: What