Google agents and simple car games

Source: Internet
Author: User

Google agent: http://hi.baidu.com/habbit99/blog/item/9df5a4cc1cd8e40c01e92822.html

Simple car games:


VaR labels: wheelcollider; var wheelfl: transform; var wheelfr: transform; var wheelrl: transform; var wheelrr: transform; vaR steer_max = 20; var motor_max = 10; var brake_max = 100; private var steer = 0; private var forward = 0; private var back = 0; private var motor = 0; private var brake = 0; private var reverse = false; private var speed = 0; function start () {Rigidbody. centerofmass = vector3 (0,-0.05, 0);} function fixedupdate () {speed = Rigidbody. velocity. sqrmagnitude; Steer = mathf. clamp (input. getaxis ("horizontal"),-1, 1); Forward = mathf. clamp (input. getaxis ("vertical"), 0, 1); Back =-1 * mathf. clamp (input. getaxis ("vertical"),-1, 0); If (speed = 0) {If (Back> 0) {reverse = true;} If (Forward> 0) {reverse = false ;}}if (reverse) {motor =-1 * back; brake = forward;} else {motor = forward; brake = back ;} worker = motor_max * motor; worker = brake_max * brake; worker = steer_max * STEER; wheelfl. localeulerangles. y = steer_max * STEER; wheelfr. localeulerangles. y = steer_max * STEER; wheelfr. rotate (frontwheel1.rpm *-6 * time. deltatime, 0, 0); wheelfl. rotate (frontwheel2.rpm *-6 * time. deltatime, 0, 0); wheelrr. rotate (rearwheel1.rpm *-6 * time. deltatime, 0, 0); wheelrl. rotate (rearwheel2.rpm *-6 * time. deltatime, 0, 0 );}

1. In reality, the car is not so good to drift. The drift requires the combination of low friction and good suspension system between the tire and the ground.

2. it is not realistic to fully simulate the mechanics engine in the game. Because drifting requires superb skills in reality, you cannot expect players to have professional skills to manipulate or modify your car, in case you forget to pull the handwheel or pull it too long =. =. In addition, the complete physical simulation not only requires the human brain to design, but also the computing of computer resources. Besides, it is not a professional simulation game such as Microsoft simulated flight.

3. numerous failuresCodeAfterwards, I found that the high-speed mobile cars will suddenly turn sideways. This is not a problem with the game engine. I checked a lot of car rollover accidents. This exists objectively, that is to say, a car that can be moved requires a stable and accurate car architecture and a very low chassis (I tried this, but it is useless in U3D, and the center of gravity and chassis are almost stuck to the ground, turning will turn sideways at high speed), professional Suspension System (this is very important, which cannot be simulated in the game), and precise debugging of each part, there are also a lot of car auxiliary systems (which will be explained later ).

4. rollover is inevitable, but players are not allowed to flip the pages if they make some misoperations in the game, which greatly affects gameplay. I tried to use the method of increasing gravity to prevent rollover, but increasing gravity increases friction, and it is more difficult to use a physical engine to simulate drift.

5. The automatic stabilizer bar system (ASBs) can effectively prevent rollover, but is it necessary for a game to be so troublesome?

 

After several days of research, I have developed several sets of drift solutions (I developed the last one, focusing on the last one)

 

Solution 1. The whole racing car simply uses translate for coordinate movement. This is to ignore the practices of the physical engine of wheelcollider. It is suitable for beginners and is simple and convenient, but there will be a lot of problems to solve in the future development (if you want to solve these problems ).

Solution 2. Use the suspension setting and friction setting of the wheelcollider. This should be the most standard, but I have never figured out how to set his forward friction and sideways friction, and what effect these settings have =. =, official racing examples won't drift at all ). Of course, this method of moving is to use the motortortorque of wheelcollider for moving (this should be the official Hope ).

Solution 3.The wheel also uses the wheelcollider, but the power of automobile movement does not use the motortortorque of the wheel. Instead, it uses force to drive the car's Rigidbody (the official example is this, this is what I think is incredible. It only means that the official team also knows that there is still a problem with his wheelcollider engine ). It is advantageous to use force. You can perform force analysis when turning, calculate the force direction and size of the last side slide, and calculate the vehicle power direction and slide judgment in real time. The only problem is the stability of vehicles. It is difficult to ensure the stability of high-speed vehicles. It is impossible to develop an ASBs system by yourself -.-.

Solution 4. This is my method. It is processed in a mix of wheelcollider and translate. First of all, all vehicles must use the functions provided by the wheelcollider to move and turn (for more information, see my log on the wheelcollider). The wheelcollider method can be used to ensure normal vehicle movement, but it will not drift (either too fast to roll over or directly turns over). To judge the drift, you only need to determine the turning angle and inertial direction of the car when the player clicks the handbrake, use transform. translate is used to get rid of tails, effectively avoiding unnecessary friction judgment and physical judgment. I will draw a picture to show the general principle of drift (cloud sister will be very happy to see it ^ ):

Because the friction and centrifugal force produced by the front and rear wheels of the handbrake wheel change the force direction of the whole vehicle, the movement direction of the car changes, causing drift. Let's assume that he is not a handbrake, but an ordinary brake, only the brake deceleration effect, so he first uses the wheelcollider for normal turning and deceleration, then write a traslate to move the object in the expected direction, when the handbrake button is pressed, it is determined that the forced object is moved and simulated to slow down the movement to produce the drifting friction attenuation effect (the coordinate movement of transform is not affected by the physical engine, so it is easy to write .)

In this way, the combined effect will produce the initial frame of the drifting effect. Gamers are easy to operate and developers are easy to develop. The last task is to debug some data to change the user experience.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.