在2D赛车经理游戏中模拟赛车
我正在研究2D赛车经理游戏。我在模拟赛车方面面临问题。我用一条赛车线创建赛道,所有汽车都会遵循它。对于大曲线,汽车移动的外观光滑,但是对于小曲线,移动不是自然,它移动太快了。 汽车进入曲线时如何管理速度?谢谢
编辑:我在游戏中忽略了物理,没有幻灯片或漂移
I am working on 2d racing manager game. I am facing a problem on simulate racing. I create the race track with a racing line which all car will follow it. For large curve, the car moving look smooth, but for small curve, the moving is not nature, it move too fast.
How can I manage the speed when the car enter curve? thank you
edit: I ignore physic in my game, there is no slide or drift
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于赛车轨道的每个点,都有绝对的最大速度。超过速度的情况将导致汽车滑动或滚动。这种最大速度是许多事情决定的 - 赛车线的那一刻半径,汽车有多少抓地力(轮胎的良好,汽车从扰流板中有多少垂直力,轨道表面),多少质量汽车有质量中心所在的地方。如果您想要极其现实的物理学,那将是极其复杂的。但是,您的代码非常简单,您将获得“足够好”的结果。
确定绝对最大值后。赛车线上的每个点(对于每种类型的汽车)的速度;您需要考虑到汽车的刹车的效果,需要“向后涂抹”。要理解我的意思,假设您的轨道很长,然后是非常紧(90度)的右转;汽车具有“无限”最大的地方。速度在直和50 km/h的最高速度上。转弯处的最慢点的速度。为了确保汽车能够及时放慢,您可能最终会在转弯前的55 km/ha仪表,转弯前2米/小时,等等。 max_speed_to_slow_down_in_time); 。
请注意,您实际上不需要确定实用的最大值。赛车线上的每个点速度。这足以选择一些要点(例如,每米的轨道)和它们之间的插值(例如,如果汽车是前“ 50 km/h”点之间的40%和未来的“ 80 km/h”点,则可以说汽车的最大速度为“ 0.4 * 50 +(1-0.4) * 80 = 68 km/h
” 您可以手工欺骗并分配“最大速度/S”)。
比赛开始(如果您的汽车都相同, 他们发生了机械故障,因为他们在轨道上停下来,因为轨道上有危险,因为它们只是离开了起始网格等)。沿新路径的最大速度。 - 获取),或假设实际最大值作弊。速度是“赛车线上的实用最大速度 - 距赛车线 *某物的距离”,或者欺骗更多(假设汽车在赛车线上就在赛车线上)。
For every point along the racing track there is an absolute maximum speed; where exceeding the speed will cause the car to slide or roll. This maximum speed is determine by many things - the radius at that point in the racing line, how much grip the car has (how good tires are, how much down-force the car has from spoilers, track surface), how much mass the car has, where the car's center of mass is. If you want extremely realistic physics it'll be extremely complicated; but you get "good enough" results with a very simple code.
Once you've determined the absolute max. speed at each point on the racing line (for each type of car); you need to "smear it backwards" taking into account how good the car's brakes are. To understand what I mean, assume you have a long straight piece of track followed by a very tight (90 degree) right turn; where the car has "infinite" max. speed on the straight and 50 Km/h max. speed at the slowest point on the turn. To ensure the car can slow down in time you might end up with 55 Km/h a meter before the turn, 60 Km/h at 2 meters before the turn, etc. This gives you something like
practical_max_speed = min(absolute_max_speed, max_speed_to_slow_down_in_time);
.Note that you don't actually need to determine the practical max. speed at every point on the racing line. It's enough to select some points (e.g. maybe every meter of track) and interpolate between them (e.g. if a car is 40% of the way between a previous "50 Km/h" point and a future "80 Km/h" point you can say that the car's max. speed is "0.4 * 50 + (1 - 0.4)*80 = 68 Km/h".
Of course all of this can be pre-determined (for each track, for each type of car) before the race starts (and you could just cheat and assign "max. speed/s" at various points by hand if all your cars are the same).
The problem is that sometimes cars go off of the racing line (e.g. to overtake, because they had mechanical failures, because they're making a pit stop, because there's a hazard on the track, because they just left the starting grid, etc). For this you can dynamically generate a new path and do all the calculations needed to determine practical max. speed along the new path. Alternatively (if you don't care so much about perfect physics and just want a game that's fun) you can cheat by having pre-defined alternative paths (e.g. maybe 3 specific corners where cars can over-take), or cheat by assuming the actual max. speed is the "practical max speed on racing line - distance from racing line * something", or cheat even more (assume cars are on the racing line when they aren't).