• 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 Oniony · May 15, 2014 at 06:38 PM · movetowards

Is there anything more efficient that MoveTowards for moving multiple units?

I'm making an RTS-type game where the player can control hundreds of units at a time. All of the units have rigid bodies on them so they can interact with one another as well as various attacks and such.

Once selected, the player can right click to have all of the units move to that spot. The problem is this: Once the player right slicks, every single unit is using a MoveToward line of code in their own individual script and this seems to slow things down a bit.

Is there any way that is more efficient to do this? I was thinking of trying to make some sort of movement system that pushes the units using velocity, but I have no idea how I would do it.

Here's an example video of my game if you need more help picturing what I'm talking about: http://youtu.be/aDSwSg90mhI

Comment
Add comment · Show 4
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 fafase · May 15, 2014 at 06:42 PM 0
Share

Are sure the pb comes from $$anonymous$$oveTowards? This is a pretty simple method only using basic arithmetic so even a hundred of object should not really kill the game if your computer is pretty decent.

avatar image Oniony · May 15, 2014 at 06:45 PM 0
Share

True. $$anonymous$$y own pc can move around 500 units without any slowdown, but on slower computers, you get bad framerate with as few as 150 units.

avatar image fafase · May 15, 2014 at 06:56 PM 0
Share

In this case, it is related to the computer but you could save some resources by coupling units. You get under one parent object and only that one gets the $$anonymous$$oveTowards. You still animate them independently so it does not look too much of a military parade.

You could simply all rotate them towards target and move the whole block of units. Then you still animate them independantly but the whole movement is done once on the parent object.

avatar image robertbu · May 15, 2014 at 07:13 PM 0
Share

If you have pro, profile it. If you don't have pro, run some experiments. As a start replace all of your units with cubes with a very simple texture...unlit/texture for example and run it. Does it slow down? If not, how many does it take with a simple texture to slow them down? What happens if you remove the Rigidbody component? I guessing its not the $$anonymous$$oveTowards() in particular that is causing the problem, but the number that are moving combined with the material and/or the Rigidbody. Once you've isolated the factor(s) that are causing the slowdown, you can look for a solution.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Random an Array to push to another Array 0 Answers

Sprite with rigidbody2d wont "glide" when gravity is 0 1 Answer

StreamReader returning incorrect results 0 Answers

On carachterspawn level load error? 0 Answers

Save Timer HighScore 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