Artificial intelligence for racing games under open streets (2)

Source: Internet
Author: User

Establish Transportation:

Create a Road Using Cubic Spline Interpolation.Under normal driving conditions,All vehicle buckets are placed on a two-dimensional curve..This curve definesXzPrecise routes for plane driving.We useHermiteCurve as our interpolation spline,Because the defined parameters,Start,The ending point and direction vector are easy to calculate.,It also has good readability.(Press:Actually usedCatmull-RomSplines can fulfill our requirements.,AndCatmull-RomSplines are more widely used.).

since the lanes of each road are composed of a vertex list , child segments of a road can be conveniently extracted from the vertex sequence . when a vehicle moves from one road to another , the new spline will be calculated to indicate the path that the car will travel next time . splines can also be used when a vehicle needs to be driven back (recovery routes) used in the road . when this type of road returns, , , used for return . using splines allows other vehicles to drive smoothly along a curve .

Maximum speed limit for creating roads: Ben Yao.AIEach road has a speed limit to determine that the vehicle can open multiple blocks on the road..In addition,Each vehicle has a random value used to determine the value of the driving speed exceeding or below the limit..This positive and negative value allows computers to drive at different speeds.(Stay realistic).

When a car needs Acceleration,It uses5. M/s ^ 2 ~ 8. M/s ^ 2A random value.In addition,When transport needs to slow down,It may have encountered a stop sign.(Stop sign ),Or when traffic lights,It will calculate1Acceleration value to be given when the target speed is reached in seconds.Acceleration is given by the following formula.:

(V2-V02)/2 (X-X0)

VTarget speed, V0Current Speed, (X-x0)To complete the deceleration distance.

Collision Detection. When CPU When time allocation is tight , A vehicle cannot perform Collision Detection on all other vehicles. . Compromise between performance and Performance : Each car only saves one car pointing to the front of its road . Within the time of each frame , Check whether the distance between yourself and the car in front is too close. , If yes , The next car will slow down . After the distance between the two is long enough , The next car will drive at the original speed .

This simplificationAlgorithmIt will cause a collision between multiple vehicles. , We can do this before a chain collision. , Stop them. , This problem is solved. (The problem can be solved by stopping the ambient vehicles at the intersections preceding the crash scene, Maybe we should translate it like this. , Haha .)

Crossing intersection.When a car reaches the end of a road,It must cross an intersection.To cross the intersection,Transport by the following four conditions:

1) Vehicle transportation must be recognized by road traffic control . The intersection of the Road contains the traffic control that describes the road. , Some suitable control types are : Do not stop (Nostop ), Always stop (Allwaysstop ), Traffic light , Stop flag (Stopsign )( See figure 2. ). If " Always stop " Flag Set , Transportation means will never get approval for entering this intersection . If " Traffic light " Set , The vehicle will allow access to the intersection when the traffic direction is green. , When " Stop flag " When setting , Transportation will wait a long time to cross this intersection .

 

Figure 2: In this case , Trafficlight Class Set traffic to a red light , Do not pass , Set the green light for other vehicles / Yellow light , Allow them to cross intersections , Lane on the left , Turn left , On the right ] Lane , The car will go straight .

2) Second approval stage (Approval Group) Yes accident Manager . The accident Manager stores the routes of all vehicles at the intersection and connected roads. . If any accident occurs , The request to pass the intersection will be rejected. . If nothing happens , The vehicle will be approved in the third stage. .

3)In the third step, you need to check whether the car has enough space to enter the next road.,At least half of it will not be at the intersection after it enters this path.

4) The fourth step is to check whether there are other means of transportation trying to cross the intersection. . Let's give an example to illustrate its necessity. : When a car stops from a vehicle (Stop sign) When the road is switched to a main road controlled by a traffic light . Because the stop sign is based on the waiting time at the intersection. , But in fact, this car will not be allowed to leave the current road until the traffic light on the main road permits it to pass. ( Press : In fact, this example is not intuitive. , Use traffic lights as conditions to check whether other vehicles try to cross , In fact, there may be some situations )

 

-----------

The technical cabin of turtles and donkeys are original. For more information, see the source.

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.