2013-08-22 3 views
0

상자 바디와 각 충돌/접촉에서 볼을 움직여서 계수를 1.1만큼 증가시키는 im. 속도를신체의 제한된 선 속도 andengine box2d

코드를 제한 할 수없는 속도가 증가하지만 메신저 :

public static final FixtureDef _BALL_FIXTURE_DEF=PhysicsFactory.createFixtureDef(0, 1.0f, 0.0f, false, _CATEGORYBIT_BALL, _MASKBITS_BALL, (short)0); 
_ballCoreBody = PhysicsFactory.createCircleBody(_physicsWorld, _ballCore, BodyType.DynamicBody, _BALL_FIXTURE_DEF); 
_ballCoreBody.setAngularDamping(0); 
_ballCoreBody.setLinearDamping(0); 
_ballCoreBody.setActive(true); 
_ballCoreBody.setBullet(true); 
_ballCoreBody.setGravityScale(0); 
this._scene.attachChild(_ballCore); 
this._physicsWorld.registerPhysicsConnector(new PhysicsConnector(_ballCore, _ballCoreBody)); 

contactListener

if(x1.getBody().getLinearVelocity().x<15.0f && x1.getBody().getLinearVelocity().y<15.0f) 
x1.getBody().setLinearVelocity(new Vector2(x1.getBody().getLinearVelocity().x*1.2f, x1.getBody().getLinearVelocity().y*1.2f)); 
else 
x1.getBody().setLinearVelocity(new Vector2(x1.getBody().getLinearVelocity().x/1.1f, x1.getBody().getLinearVelocity().y/1.1f)); 

내부 내가 어떻게 이것을 달성합니까?

답변

0

내가 볼 수있는 것은 코드에서 속도가 전혀 들리지 않는다는 것입니다. 접촉 청취자 내부는 속도가 15.0 미만이고 계수가 1.1 일 때 계수 1.2로 증가하므로 충돌 할 때마다 속도가 지속적으로 증가합니다. 이 방법이 더 적합 할 수 있습니다. 코드를 테스트하지 않았으므로 조정할 필요가 있습니다.

float xVel = x1.getBody().getLinearVelocity().x; 
float yVel = x1.getBody().getLinearVelocity().y; 

//if you want to be sure the speed is capped in all directions evenly you need to find 
//the speed in the direction and then cap it. 
bool isBelowMaxVel = (xVel * xVel + yVel, * yVel) < 225.0f; //15 * 15 = 225 // this is to avoid using a square root 

if(isBelowMaxVel) // only increase speed if max not reached 
{ 
    x1.getBody().setLinearVelocity(new Vector2(xVel * 1.1f, yVel * 1.1f)); 
} 
관련 문제