汽车转向算法?
我已经问过类似的问题,但现在我遇到了管理和实现简单的 2d(自上而下)赛车游戏的“现实”转向的问题。
我怎样才能为汽车做一个“现实”的转向? (我使用 C#,但欢迎使用其他语言;)) 使用正弦和余弦? 如果是,怎么办? 提前致谢!
i've already asked something similar, but now i've the problem to manage and realize a "realistic" steering for a simple 2d (top-down) car racing game.
How can i do a "realistic" steering for the car ? (i use c# but another language is welcome;))
Using Sin and Cos ?
If yes, how ?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能想使用其他人已经创建的物理引擎。我听说过有关 XNA 的好消息物理API。
我想你将不得不使用正弦和余弦,但这只是非常大的冰山一角......
You will probably want to use a physics engine that someone else has already created. I've heard good things about the XNA Physics API.
I would imagine that you will have to use sine and cosine, but that is the just the tip of a VERY large iceberg...
算法是:
记录其他人如何驾驶(使用游戏的开发版本)
(可选)将记录分割成片段以供各种使用常见情况。
在游戏中重播录音。 (使用合适的片段并可能在它们之间插入轨迹)。
您也可以尝试模糊逻辑和简单的转向单元模型。
模型是:
Algorithm is:
Record how someone's else drives (using dev. version of game)
(Optional) Split up recording into snippets for variety of usual situations.
Replay recordings in game. (Using suitable snippets and possibly interpolate trajectory between them).
You may also try fuzzy logic and simple steering unit model.
Model would be:
我正在午休,所以我无法对“最佳”答案做出巨大的公正,但伪代码看起来像这样:
您将在每一帧中执行此代码;旋转将由您的转向输入控制,速度将由您的加速度输入控制。
I'm on my lunch break so I can't do tremendous justice to the "best" answer, but the pseudocode looks something like this:
you would execute this code in every frame; rotation would be controlled by your steering input, and speed would be controlled by your acceleration input.
Brian Driscoll 十年前的有用答案对于要求不高的应用程序来说,您只需要了解这一点即可。我经常使用通过速度矢量对位置进行欧拉积分,并通过控制器的加速度进行修改。
轮式车辆的一个有趣的特点是它们不会绕重心旋转。典型的汽车绕着后轴线上的一个点旋转,但很好地向侧面偏移。
这个概念对于真实车辆很重要。他们的转向机构试图符合阿克曼转向几何,以尽量减少滑动造成的磨损。在模拟车辆中,这些考虑因素对于建模瞬时曲率和预测未来路径非常重要。
Brian Driscoll’s helpful answer ten years ago is all you need to know about this for non-demanding applications. I often use Euler integration of position via velocity vector as modified by accelerations from a controller.
An interesting sidelight for wheeled vehicles is that they do not rotate around their center of gravity. A typical car rotates about a point along the line through the rear axle, but offset well to the side.
This concept is important for real vehicles. Their steering mechanism tries to conform to Ackermann steering geometry to minimize wear due to slip. In simulated vehicles these considerations are import for modeling instantaneous curvature and predicting future path.