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 Hullu · Nov 16, 2014 at 01:52 PM · movementailagcharacter controllerstandalone

Simple movement causing lag (on standalone)

I have 100 AI simply moving towards player. First i used character controllers to move the AI (with SimpleMove). FPS dropped to 28. Then i removed the SimpleMove from the script and had only look rotation. FPS stayed at 60. So, problem seems to be at moving the AI.

I tried with rigidbody + capsule collider and moved the AI with transform.Translate. Again FPS dropped to 28.

So what could cause this?

EDIT: I tried with only transform.Translate. On editor i had +60 fps. When i build the game, it is like a slideshow...

Comment
Add comment · Show 5
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 MrSoad · Nov 16, 2014 at 02:42 PM 0
Share

Are you caching your transfroms, with 100 AI objects this could speed things up a bit if you are not.

avatar image Hullu · Nov 16, 2014 at 02:50 PM 0
Share

I have not. i will look into that. Thanks!

Edit: Im not sure if did the caching right, but i did not work...

avatar image Linus · Nov 16, 2014 at 06:24 PM 0
Share

Show the relevant code

avatar image Hullu · Nov 16, 2014 at 06:52 PM 0
Share

This is on Void Update()

 case VisualState.InSight:
 
 dir = target.position - myTransform.position;
 if(can$$anonymous$$ove)
 myTransform.Translate(Vector3.forward * Time.deltaTime * speed);
 rotation = Quaternion.LookRotation(dir);
 rotation.x = 0;
 rotation.z = 0;
 myTransform.rotation = Quaternion.Slerp(myTransform.rotation, rotation, Time.deltaTime * rotationspeed);
 
 break;
 }

AI does have about 10 colliders with rigidbody (on $$anonymous$$inematic when alive) for the ragdoll physics.

avatar image Hullu · Nov 16, 2014 at 09:35 PM 0
Share

Interesting, it works very well on on editor. On build version fps drops to 1.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by toddisarockstar · Nov 16, 2014 at 09:41 PM

I believe just line 6 slowing you down. calling Quaternion.LookRotation every frame is too much. try refreshing the rotation variable every ten frames or so. and you pry wont notice a difference with slerp.

put line 6 in a timer like this:

if (timer==0){rotation = Quaternion.LookRotation(dir);}

if(timer==0){timer = 10;} timer=timer-1;

Comment
Add comment · Show 3 · 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 Hullu · Nov 16, 2014 at 09:49 PM 0
Share

I already stated that there is no lag when only rotation is working. I have now got it working on editor, but for some weird reason build version is unplayable...

avatar image toddisarockstar · Nov 16, 2014 at 09:58 PM 0
Share

reading javascript or checking variables wont slow down a game. but asking for funtions from the game engine takes a second for the cpu to calculate and get back. normally it would make no difference but you are multiplying by 100.

some are worse than others but other examples to watch out for in your game is raycasting and asking for Vector3distance. I have a game with 50-100 objects and used timers to limit exectly how often these funtions where called. it greatly helped my project keep going!

avatar image Hullu · Nov 16, 2014 at 10:17 PM 0
Share

Your script did not increase the fps :/ Thanks anyway.

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

29 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Zombie AI Lag when checking if it should jump 1 Answer

Controlling AI Movement 0 Answers

2D sprite movement jagger 1 Answer

Should you use CharacterController.Move or SimpleMove for enemies? 1 Answer

What’s the simplest way to find nearest navmesh targets? 0 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