Thursday, November 8, 2018

Simple 2D Flight Physics with Box2D


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 flys 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?


Thanks!



Answer



Iterative empirical testing. Add some test sliders to your GUI that control the force applied for the upward and downward directions.


Other than that, consider changing the way force is applied. Add gravity into the mix, when the plane is horizontal its lift offsets gravity. The lift decreases with change in pitch. Your force is always forward, when pointing down it's in addition to gravity, when you're pointing up gravity is subtracted from the force.


Basically, think about how to make it more realistic if you want it to feel more realistic.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...