我想让一个形状从中间底部移动到我正在触摸的点。问题是解决触摸点的角度(或度数?)。
float angle = ?
float power = calculatePower(touchY);
Vec2 impulse = new Vec2(angle, power);
Vec2 point = body.getWorldCenter(); // to prevent rotation of shape
body.applyLinearImpulse(impulse, point);
有人有建议吗?
编辑:已解决
感谢安德鲁斯的回答。这是工作代码:
Point delta = new Point(touchX - bodyX, touchY - bodyY);
double angle = Math.atan2(delta.y, delta.x);
Vec2 direction = new Vec2((float)Math.cos(angle), (float)-Math.sin(angle));
float power = calculatePower(touchY);
Vec2 impulse = new Vec2(power * direction.x, power * direction.y);
Vec2 point = body.getWorldCenter();
body.applyLinearImpulse(impulse, point);