开发者

Car / Vehicle Drifting Around Corners in Overhead Racing Game

开发者 https://www.devze.com 2023-03-29 19:50 出处:网络
I\'ve implemented a pretty basic car movement system: _velocity.x = Math.cos(angleAsRadians) * _speed;

I've implemented a pretty basic car movement system:

_velocity.x = Math.cos(angleAsRadians) * _speed;
_velocity.y = Math.sin(angleAsRadians) * _speed;

_position.x += _velocity.x;
_position.y += _velocity.y;

You mov开发者_运维百科e by increasing / decreasing speed and turn by increasing / decreasing the angle.

How can I add drifting so that the faster I'm going, as I turn, the more I drift? I can't figure it out and there's next to no other google-able sources.

Ideas?


Car physics are a bit tricky. What you need is to implement a slip based physics engine.

This article explains the process fairly well. In order to make it work properly one needs to take into account the rotation of the wheels and the difference of forces when the tyre is going one way and the ground goes another direction. This turns out to be two forces, one perpendicular to the axis of the wheel and one going sideways in regards to the car.

Of course, this is a lot of work, and when doing anything games-related the general rule is if it looks good it is good. So, one can get some mileage and ideas from how the actual physics is done and take some bits and pieces of the proper solution in order to create a believable facsimile of the real deal.


Decide upon a "coefficient of drift", like a distance that's 0.5% of the velocity times time.

_position.x += (1+coeff)*_velocity.x; ->  _position.x += (1+0.005)*_velocity.x;
_position.x += (1+coeff)*_velocity.y; ->  _position.y += (1+0.005)*_velocity.y;

So in this case it's additive, and is based on the velocity.

This coefficient could also be variable based on something like the track radius, any racetime conditions (slippery, etc), differs between x and y axis, and randomized to be plus or minus.

0

精彩评论

暂无评论...
验证码 换一张
取 消