我想在我的游戏中添加一个黑洞功能,但我仍然坚持吸引力的计算。
但实际上我的物体并没有被黑洞吸引,他们一点一点地离开中心
这是我的代码:
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));
}