使用Box2D进行简单的2D飞行物理 [英] Simple 2D Flight Physics with Box2D

查看:72
本文介绍了使用Box2D进行简单的2D飞行物理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用飞机作为玩家来构建一个简单的侧面滚动器.因此,我想用简单但具有逼真的感觉的物理学来构建简单的飞行控制.我正在使用cocos2D和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.

我正在根据用户的输入向平面施加力(这是一个 b2CircleShape ).因此,基本上,如果用户向上推,则会调用 body _-> ApplyForce(b2Vec2(10,30),body _-> GetPosition()).同样,对于-30,则使用

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?

推荐答案

我最终简化了在飞行中施加的基本力:即推力,阻力,升力和重力.

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

我做了以下简化:

  1. 阻力和推力不必是两个力,而是推力的大小由当前速度调整(类似于安德鲁对airResistance的建议).
  2. 重力由box2d中的World对象处理.
  3. 举升是相等的,但与重力相反(飞机在水平飞行时).
  4. 推力"和升力"是根据平面的角度设置的:基于物体的变换R列.

现在,用户只需控制飞机的角度,然后调整推力和升力,并更新世界模拟.

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.

这篇关于使用Box2D进行简单的2D飞行物理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆