我在box2d试验床上用绳索连接了一个动态体和一个静态体。我想让动态体在按下'a‘或'd’时围绕静态体旋转。我不想使用旋转连接,因为旋转连接的长度是固定的。所以我想对物体施加离心力,有人能告诉我怎么做吗?提前谢谢。
发布于 2015-01-30 15:08:34
我对testbed不熟悉,但是你问的问题背后的逻辑是相当简单的。你要做的是找出动态体和静态体之间的角度。有了这个角度,你只需创建一个新的Vector2(x,y),它将代表你在ApplyForce中使用的力。
在java中,它看起来像这样:
// This is the dimension of the vector representing the applied force (you choose that)
float forceDimension = 10;
// This is the angle you have to find (I use PI since the Math class uses radians)
// PI radians == 90 degrees (your dynamic body would then be directly above your static body)
double angle = Math.PI;
// This is the actual vector of the force
Vector2 force = new Vector2(forceDimension * (float) Math.sin(angle), forceDimension * (float) Math.cos(angle));https://stackoverflow.com/questions/27583290
复制相似问题