Simple 2D Flight Physics with Box2D

℡╲_俬逩灬. 提交于 2021-02-11 12:20:37

问题


I'm trying to build a simple side scroller with an airplane being the player. As such, I want to build simple flight controls with simple but realistic-feeling physics. I'm making use of cocos2D and Box2D. I have a basic system working, but just can't get the physics feeling correct.

I am applying force to the plane (which is a b2CircleShape) based on the user's input. So, basically, if the user pushes up, body_->ApplyForce(b2Vec2(10,30), body_->GetPosition()) is called. Similarly, for down -30 is used.

This works and the plane flies along with up/down causing it to dive or climb. But it just doesn't feel right. There is no slowdown on climbs, nor speed up during dives. My simple solution is far to simple.

How can I get a better feel for a plane climbing/diving?


回答1:


I ended up simplifying the basic forces that apply in flight: Namely thrust, drag, lift and gravity.

I did the following simplifications:

  1. Drag and thrust do not need to be two forces, instead thrust's magnitude is adjusted by the current speed (similar to Andrew's suggestion of airResistance).
  2. Gravity is handled by the World object in box2d.
  3. Lift is equal but opposite of gravity (WHEN the plane is flying level).
  4. Thrust and Lift are set based on the angle of the plane: based on the body's transform R columns.

Now, the user only controls the angle of the plane, then the thrust and lift forces are adjusted and the world simulation is updated.

This gave a good feeling simulation but greatly simplified.




回答2:


I would go with that:

float engineForce(/* possibly some params */)
{
    return SOME_CONSTANT;
}

float airResistance(float velocity /* possibly more params */)
{
    return CFT * velocity;
}

float resultForce = std::max(engineForce() - airResistance(), 0);

Using such approach you are able to tune your system easily playing with two functions



来源:https://stackoverflow.com/questions/11090677/simple-2d-flight-physics-with-box2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!