我正在尋找在我的遊戲中添加黑洞功能,但我卡在吸引力的計算。Box2d BlackHole吸引力
但實際上我的對象沒有被黑洞吸引,他們會遠離中心一點一點
這裏是我的代碼:
public void applyVortexForce(PhysicBody bodyCollider) {
Vec2 speed = this._physicBody.getBody()
.getLinearVelocityFromWorldPoint(
bodyCollider.getBody().getWorldCenter());
speed.mul(1.8f);
Vec2 currentSpeed = new Vec2(bodyCollider.getBody()
.getLinearVelocity().x, bodyCollider.getBody()
.getLinearVelocity().y);
Vec2 diff = speed.sub(currentSpeed);
currentSpeed = currentSpeed.add(diff);
currentSpeed.mul(bodyCollider.getBody().getMass());
bodyCollider.getBody().setLinearVelocity(
new Vec2(currentSpeed.x, currentSpeed.y));
}
所以,你想一個反向漩渦? – 2013-04-07 10:48:55
我想要物體進入旋渦狀,就像黑洞一樣,我的代碼在外面 – kakou 2013-04-07 11:37:13