汽车转向算法?

发布于 2024-09-29 04:00:46 字数 131 浏览 1 评论 0原文

我已经问过类似的问题,但现在我遇到了管理和实现简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

美男兮 2024-10-06 04:00:47

您可能想使用其他人已经创建的物理引擎。我听说过有关 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...

︶葆Ⅱㄣ 2024-10-06 04:00:47

算法是:

  1. 记录其他人如何驾驶(使用游戏的开发版本)

  2. (可选)将记录分割成片段以供各种使用常见情况。

  3. 在游戏中重播录音。 (使用合适的片段并可能在它们之间插入轨迹)。

您也可以尝试模糊逻辑和简单的转向单元模型。

模型是:

x = integrate horiz_velocity by t
horiz_velocity = intergate steering_angle by t
and steering_angle = fuzzy_steering_function(...)

Algorithm is:

  1. Record how someone's else drives (using dev. version of game)

  2. (Optional) Split up recording into snippets for variety of usual situations.

  3. 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:

x = integrate horiz_velocity by t
horiz_velocity = intergate steering_angle by t
and steering_angle = fuzzy_steering_function(...)
北方的韩爷 2024-10-06 04:00:46

我正在午休,所以我无法对“最佳”答案做出巨大的公正,但伪代码看起来像这样:

y_change = sin(rotation) * speed;
x_change = cos(rotation) * speed;

car.x += x_change;
car.y += y_change;

您将在每一帧中执行此代码;旋转将由您的转向输入控制,速度将由您的加速度输入控制。

I'm on my lunch break so I can't do tremendous justice to the "best" answer, but the pseudocode looks something like this:

y_change = sin(rotation) * speed;
x_change = cos(rotation) * speed;

car.x += x_change;
car.y += y_change;

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.

我为君王 2024-10-06 04:00:46

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.

diagram of Ackermann steering geometry

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文