Want to add a "drafting" feature to my racing game.

I am doing a very very simple racing game. It is 3d but basic. I am new to Unity and game in general. I have tried using the wind feature, angular drag, and a host of other features. I am assuming it will be some complicated script to “add force” when in a certain range of the vehicle. If anyone can point me in the right direction, I would really appreciate it.

Actually a pretty interesting and complex topic. You have two stages: Determine whether to apply this effect to this car this frame, and determine what behaviors to apply. I assume by talking about forces, you’re actually moving these cars with rigidbody physics and methods like AddForce, correct?

First determine whether to apply the effect. You could have a box collider which extends from the rear of every vehicle. It could optionally scale with velocity, growing in length to encompass a greater area. Additionally (or alternatively) you could include raycasts, distance checks, angle checks, etc to discover that you’re actually in the cone-like area behind the vehicle which would create drafting conditions. A fan-like array of raycasts might work well instead.

Once you know you should apply drafting this frame, your data from the previous steps - and additional checks for e.g. angle difference between vehicles - can inform the force vector you want to apply, or otherwise influence the behavior of the vehicle. Once you know you’re in the zone, it’s just math. Actually it’s all math. :smiley:

I’d probably ignore the box collider part / fan-of-raycasts unless you’re dealing with tons of vehicles - because it sounds kinda messy - and just start with a distance check. That should filter out most vehicles that are ineligible so they don’t run the rest of the code needlessly. The distance required should scale based on the other car’s velocity. You can always change the discovery method later.

Next you want the angle difference between the other car’s forward motion and this car’s forward motion. Not forward direction, in case the cars are in reverse or something odd like that, but forward motion, (rigidbody.velocity).

The distance and angle difference tells you you’re in the zone and should apply drafting. It does kinda make sense that the effect should reduce drag, so I think I’d try that first. How much to reduce drag can be influenced by the other three variables you just finished testing. Use lerps and ranges to find a good value, e.g.

float drag = Mathf.Lerp( 10, 5, percentThroughDraftingEnvelope );

Depending on how detailed you’d like to be, you can add additional complexity to this approach, like raycasts to test for interfering objects, and complex envelope calculations which more firmly establish the physical situation so you can respond with greater accuracy.