Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Turzoxpress · Aug 28, 2016 at 10:45 AM · androidaicarracingtraffic

How to implement traffic system efficiently in Unity game to run smoothly on mobile device?

Recently developing a racing game, game is fine but when i added traffic system (AI cars with waypoint following) the game becomes laggy ans slow. I used almost 300+ more cars with rigidbody and box collider attached. I searched about solution of the problem : Some said it's the amount of rigidbnody or collider for making the game slow. But if I remove colliders then I won't be able to detect the collision between my main player's car and AI traffic cars. Any solution or suggestion ?

Comment
Add comment · Show 1
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 misher · Sep 05, 2018 at 06:27 AM 0
Share

You can also try new unity entity component system, this can help you to spread all your traffic cars behaviours in background threads. Another think to mention is that why should your traffic system control all 300 cars using physics, you may optimize it a lot if turning on physics for cars only in proximity to the player(s) and all other distant cars can be handled by simple translations and rotations, also you should definitely use LOD for traffic car 3d models.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Turzoxpress · Aug 29, 2016 at 01:44 PM

Problem Solved!

I used Unity Profiler to check the main cause of slowing the game. I found that I have a common script for the 300 traffic cars to follow a certain waypoints. That scripts updated every frame, that's why the game became slow.

Solution :

  1. I moved the waypoint follower code from Update function to LateUpdate, for this, the game doesn't get hanged while starting the game cause LateUpdate always calls after all Update functions have been called.

  2. Then I measured the distance between my Player car and each traffic cars, I take a minimum distance (in my case : 130m ) between Player car and a traffic car so that which traffic cars are away from this certain distance are inactive. I mean I make them active when they are in 130m range and make them inactive while they are not in that range.

And now my game becomes way faster!

Comment
Add comment · Show 1 · 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 AsadShokat · Sep 05, 2018 at 04:58 AM 0
Share

i am new in untiy and i have no idea of distance findin you do in your game . can you plz send me the following task code Turzoxpress Then I measured the distance between my Player car and each traffic cars, I take a $$anonymous$$imum distance (in my case : 130m ) between Player car and a traffic car so that which traffic cars are away from this certain distance are inactive. I mean I make them active when they are in 130m range and make them inactive while they are not in that range.

And now my game becomes way faster!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a Lapping System for a Car Game 1 Answer

AI car Script problem 1 Answer

AI Car Problem 1 Answer

Ai turning problem on Android - Question solved 0 Answers

How To Add AI To Car/Racer? 4 Answers


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