Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by siddharth3322 · Apr 24, 2014 at 04:42 AM · loadingracingunity4.3track

Racing Game Track Generation

Right now, I am developing racing game in 2D that is similar to Road Fighter.

For this I want to create fixed level game play. I have some confusion in mind for track generation.

I have two consideration in mind but which one is best for me that I can't able to decide.

  1. Load whole racing track in start of game

  2. Load one segment of track at a time and generate next one based on car movement

Implementing first approach is simple one but if I choose second one then how to store data about each segment and car, power up and obstacle information.

I want suggestion in this matter what approach I have to use for game so that it run smoothly on lower ended devices also.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by fafase · Apr 25, 2014 at 05:49 AM

if you have pro, you have Occlusion culling which means what is out of view is not render.

If you do not have it, then you can cut your track in mini parts, load them into an array and deactivate them all except the first and second ones.

Then you place trigger boxes (or check for distance) and when entering the box you deactivate the one behind and activate the one in front. In the end you always have only two parts active at a time.

Those portions of track could also include the AI cars, the ones just driving but not racing.

EDIT: Since your camera is not moving, let's see another approach.

Each portion of track is under an empty gameObject and all those empty GO are under a main empty GO. This contains the track and a script to generate cars.

All cars are generated on start and placed in a pool of objects so that you do not have to instantiate and destroy them, you simply activate/deactivate. This happens in the start.

Also in the start, all portion object are placed in a dictionary. For instance if your portions are 20 units long then it means the first is at 0, second at 20 and so on. The position is the key and the object is the value.

 public Transform mainTrackObject;
 Dictionary<int, GameObject> dict = new Dictionary<int, GameObject>();
 void Start()
 {
    foreach(Transform t in mainTrackObject){
       int key = Mathf.RoundToInt(t.position.z);
       dict.Add(key,t.gameObject);
       t.gameObject.SetActive(false);
    }
    dict[0].SetActive(true);
 }

Thanks to this you can "track" how much distance the car have done (even though it is not moving) and activate the portion.

 float distance;
 void Update(){
    distance += Time.deltaTime * velocity; // Velocity is the assumed speed of the car
    int dist = Mathf.RoundToInt(distance);
    if(dist%20 == 0){
        SetActivation.SetActive(dist);
    }
 } 
 void SetActivation(int key){
    GameObject o = dict[key];
    o.SetActive(true);
    dict[dist - 20].SetActive(false)
    // Get AI component for cars and call init method
    o.GetComponent<CarAI>().Init();
 }

If speed is constant, it is even more simple, you can simply do the activation/deactivation based on time using InvokeRepeating.

Concerning CarAI is could be a simple script with how many car and then place them on the road:

 public int amountCar;
 
 void Init(){
    for(int i = 0; i < amountCar;i++){
       GameObject car = PoolSystem.Pop();
       car.SetActive(true);
       // Position system, either random
       // using SphereCast to detect if an object is already there
       // or using an stack of predefined position on track
    }
 }

Concerning the stack pooling system I leave to you as you can find this on the internet.

THIS IS JUST GIVING YOU IDEAS, TAKING THE CODE AS IS MAY NOT WORK RIGHT AWAY, YOU MAY NEED TO TWEAK A LITTLE.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image siddharth3322 · Apr 25, 2014 at 06:52 AM 0
Share

I have unity pro. For my game, I don't move my camera but I am moving background. So occlusion culling, will give any benefit to me? Also setting this also found difficult for me.

For second approach, I have some confusion in $$anonymous$$d.I have to load all tracks in game and deactivate rest ones those are not used or put each track based on necessity.

All other data I understand what you have said. Last one, How to manage other data for each track such as cars, power ups etc?

avatar image siddharth3322 · Apr 25, 2014 at 07:49 AM 0
Share

Thanks this is more than enough for me. One last question about car plotting on track. How to place car at random position when I have variety of tracks available?

avatar image fafase · Apr 25, 2014 at 08:05 AM 0
Share

It would depend on how the portion looks. you could define an array of rect, first pick a rect randomly then pick a position randomly within the dimensions.

If your portion is straight, then only one rect is fine, if your portion is curving then you may need a few of them.

You can also place points on your track and use http://docs.unity3d.com/Documentation/ScriptReference/Random-insideUnitCircle.html

to generate a random position around that point.

$$anonymous$$ake sure to check that a car is not already there with https://docs.unity3d.com/Documentation/ScriptReference/Physics.CheckSphere.html

avatar image siddharth3322 · Apr 25, 2014 at 08:12 AM 0
Share

I have no words for this master suggestion.

avatar image
1

Answer by Noob_Vulcan · Apr 24, 2014 at 07:16 AM

I would recommend to go with 2nd choice (i myself use that technique). Use Object pooling mechanism to generate road.

Since Low end devices have RAM issues so loading whole track at once wouldn't be good idea. And one more thing Unity 4.3 support ARM 7 devices (doesn't include Ldpi).

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image siddharth3322 · Apr 24, 2014 at 11:25 AM 0
Share

Thanks for your response. In second approach how to load tracks and other game object? $$anonymous$$eans what coding standard I have to use?

avatar image Noob_Vulcan · Apr 25, 2014 at 04:28 AM 0
Share

I didn't get what you mean by coding standard... Create few track prefabs ie. say 10 then use these tracks only. You have to reposition these track prefabs again and again. I hope you got what i mean. :)

avatar image siddharth3322 · Apr 25, 2014 at 04:44 AM 0
Share

Say I have 10 tracks, For each track I want fixed data. For ex, in track 3 I want 3 red cars and 2 power ups. Then how to manage this type of data through coding?

avatar image Noob_Vulcan · Apr 25, 2014 at 05:04 AM 0
Share

you will have to use empty gameobjects say red_car_spawner , fuel_spawner. These gameobjects will be child of the track3.Now you depending on player car position you have to spawn other cars and powerups.

avatar image siddharth3322 · Apr 25, 2014 at 05:18 AM 0
Share

Thanks for your attention. I am talking about data storage of all these information.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

In sequence position game objects 1 Answer

Game Development Approach 0 Answers

GameObjects creation within boundry 3 Answers

Object sliding on the roller coaster like track 0 Answers

"Send Message Has No Receiver" On Button Click 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges