unity making racing game

Recently spent nearly half a month's time to study how to make a racing game with unity, to find a lot of information search online, beep miles beep also seen a lot of miles on video and found little useful information to death, most of them are in order to make eye makes garbage demo, no playability (simply garbage), read the unity official demo racing games and flight games, we found less can learn from them to death (basic are also a bunch of garbage, Why specifically mentioned below), the following summary of how to make a stable of racing games:

I

Some useful questions raised here, I will go one by one to solve the problem based on.

1. I want to make a kind of racing game:

    Asphalt is not possible, if Newton know of such an anti-gravity game, is estimated to be happy getting up from the coffin to play for three days and three nights.

    Because it is the first time playing games, so here I decided to do a simulation racing game, advancing forward key, back key back, left and right direction keys to play, spacebar to handbrake, shift key is the foot brake.

2. How to build the basic structure of the car:

    Here too lazy to write, direct manipulation of the official structure to build a unity.

3. How basic car control coding:

    Here too lazy to write, a lot of the Internet, is that several codes, the driving force torque, brake torque force, four-wheel drive, front and rear drive.

4. How parameters racing wheel settings:

    Many developers new to this estimate will find the time, the car will always be inexplicable bounce, will start rocking around. Because the restoring force bounce your car wheels have exceeded the tolerance of gravity, the relationship between the friction coefficient and frictional force with the gravity, frictional force is less than the force of gravity, to modify the parameters it, as the wheel parameters, in particular the longitudinal lateral friction and friction, it is recommended to go see what this area to find out the official look at the following.

5. How to prevent car rollover:

    Here we use a number of complementary physical processing way:

First, set a lower center of gravity, is disposed in the center of mass of the car rigidbody lower position.

The second: additional auxiliary pressure, where the code official reference point because there is a physical anti-complementary, do not use too much, if you want the absolute simulation, then you better not, but these players which control it.

m_WheelColliders[0].attachedRigidbody.AddForce(-transform.up * m_Downforce *m_WheelColliders[0].attachedRigidbody.velocity.magnitude);

Third: the balance bar system, where a big brother labeled specific content address. https://blog.csdn.net/u011643833/article/details/49102423

Balance bar system for racing games can be said to have great utility, to prevent skidding also played a significant role.

was WheelL: WheelCollider;
was WheelR: WheelCollider;
was Anti Roll = 5000.0 ;

function FixedUpdate ()
{
    was there: WheelHit;
    was Travell = 1.0 ;
    was Travelr = 1.0 ;

    // Calculation suspended on both sides of the tire in each case factor 
    var groundedL = WheelL.GetGroundHit (HIT);
     IF (groundedL)
        travelL = (-WheelL.transform.InverseTransformPoint(hit.point).y - WheelL.radius) / WheelL.suspensionDistance;

    var groundedR = WheelR.GetGroundHit(hit);
    if (groundedR)
        travelR = (-WheelR.transform.InverseTransformPoint(hit.point).y - WheelR.radius) / WheelR.suspensionDistance;

    // calculate the balance bar stiffness coefficient 
    var antiRollForce = (Travell - travelR) * AntiRoll;

    // tire force distribution to both sides of the 
    IF (groundedL)
        rigidbody.AddForceAtPosition(WheelL.transform.up * -antiRollForce, WheelL.transform.position);  
    if (groundedR)
        rigidbody.AddForceAtPosition(WheelR.transform.up * antiRollForce, WheelR.transform.position);  
}

 

6. How to prevent skidding car:

Here is the biggest problem of all estimated new to experienced developers, and happily knock Code, started the car, thorn slip slip on the go, cornering hard, braking can not brake, a sense of powerlessness. In fact, this is a very sad issue. Because unity is real physics engine physics simulation, and if we slip friction coefficient as high as possible transferred here, you will find still slipping, but in reality you drove to this rate will slip, also rollover serious than this, but in reality the car's speed is slower than slow start turning, etc. are excessive, so I do not feel it.

To prevent the above add additional rollover force in fact virtually has also increased friction, but the effect is not obvious; as to bring balance bar to prevent skidding effect I do not come up. So we can add some extra auxiliary force effect, although some anti-physical, but playing cool on the line. The acquired value of each wheel side slip added opposite the sliding direction of the force at each wheel of the wheel (the value multiplied by the sliding, sliding the acquired value of the variable is defined between 0 and 1), this is equivalent to friction additional lateral forces, thereby increasing the effect of preventing slipping friction. However, we feel some of the simulation game skid is not serious, because the developers have done a side track the level of processing, so the game will be canceled out when the sliding part, potentially increasing the gaming experience (here I have done experiment, put a car racing game demo experiment into the ground, slipping situation is worse than my sister game car).

Here it, because the game drift mainly from some sliding, but sliding will lead to serious gaming experience bad, so here compare PubMed developers patience.

7. those things about racing and drift and nitrogen:

In reality, only opened a motorcycle, so it looked a bit drift is to be implemented with sufficient speed and handbrake. But the game can drift a little speed (too fake). Nitrogen in the game is simply the presence of science fiction, as if suddenly the car was fitted with a rocket engine. However, the truth is actually a nitrogen cylinder engine acceleration engine for improved, in other words not usually use a little egg, which still have to rollover rollovers. Also it mentioned above is only the development of small game, if it is big game, like geta5 as a car estimated to have hundreds of peripheral parameters, it is estimated that in addition to the car programmer, no one can see clearly, so your game is justified. Here we Tucao about unity official racing game code, I have always wondered how the official is to solve the lateral slip and turns, then a Code SteerHelper (), this looked like dog feces code that people crash, it is forced to change velocity direction of the car, a side effect is that you will turn a corner serious turn, will be converted into a bad experience another bad experience, so it makes sense.

Guess you like

Origin www.cnblogs.com/xiaoahui/p/12346583.html