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
1
Question by justbecrazy · Aug 09, 2011 at 05:53 PM · transformcharactercontrollercharacter.move

Why my framerate fall down to 5-6FPS once I use CharacterController.Move()

I need to make several enemies (AI) move.

Once I use CharacterController.Move() or CharacterController.SimpleMove(), the framerate would gradually fall down to 5-6FPS (SimpleMove() would be a little better, but still not acceptable).

But if I simply use Transform.Translate(), the enemies would not be able to climb/descend along the terrain. They would rather penetrate into the terrain.

So anyone could help me find out a way out of this issue?

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

6 Replies

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

Answer by justbecrazy · Aug 10, 2011 at 03:51 PM

I finally got it!!!!!!!!!!!!!!!!!!!!!!!!!!!!After one whole day work,at last!!!!!!!!!!!!!!!!!!!!!!!!

It's all about the setting of my CharacterController. I used to set it too large in Height,Radius,....all other parameters, because my model imported is big.

And then I changed all of these stuff back into the values suggested in the official Reference page. And the FPS now is 80+ for 10 enemies!

Oh yeah!!

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 overunity3d · Aug 10, 2011 at 03:54 PM 0
Share

From weedhopper to Jedi knight with a simple click! Go with the force...

avatar image justbecrazy · Aug 10, 2011 at 03:55 PM 0
Share

Of all the parameters, the most crucial one is Radius. It would significantly drag down the FPS if it gets larger. Could someone tell me why?

avatar image Popobawa · Jul 07, 2012 at 01:21 PM 0
Share

Holly crap, you're right! I had a small model that I scaled. I set the Character Controller radius to 0.5 so it matches the sizes of a model and got 50 fps drop on Simple$$anonymous$$ove() call. Now when I set radius to 0.15 I get 70 fps again.

Unity should address this issue I$$anonymous$$HO.

avatar image deepakcue · Feb 27, 2014 at 01:13 PM 0
Share

Had you Scaled those Enemies programatically or You have Created a new Prefab's of Enemy with required sizes. I had Scaled those objects in my Prefabs only and saved them as new. For FPS should i care in these case of scaling ?

avatar image
0

Answer by aldonaletto · Aug 09, 2011 at 06:09 PM

There must be something wrong - the CharacterControllers would slow down Unity this way only if you had an entire enemy army! I bet on some coroutine being continuously called in your AI - this creates an always increasing number of coroutines running in parallel, which gradually slows down your game.
Post your AI script - only analyzing it we can help you to find the culprit.

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 justbecrazy · Aug 09, 2011 at 06:18 PM 0
Share

Thank you very much! 1.They're more or less 25 enemies right now. And I guess it would be 50 at maximum. Would that be too much to use CharacterController.$$anonymous$$ove()?

2.Do I have to use FixedUpdate(), ins$$anonymous$$d of Update(), to call CharacterController.$$anonymous$$ove()?

avatar image aldonaletto · Aug 09, 2011 at 06:32 PM 0
Share

I don't believe 25 enemies could slow down your game this way (unless it's a mobile device game - is it?)
You must use FixedUpdate to do rigidbody things (to add a continuos force, for instance), since the physics engine syncs with FixedUpdate. But the CharacterController doesn't use the physics engine, so it's better to keep it in Update. I really suspect that some out-of-control yield or StartCoroutine is the responsible for your problem.

avatar image overunity3d · Aug 09, 2011 at 06:37 PM 0
Share

Its not about the number of physical enemies but about the number of parallel processes going on.

avatar image aldonaletto · Aug 09, 2011 at 09:07 PM 0
Share

That's what I think too. This often is caused by coroutines being called at each Update - they are like the butler in these cases: always the first suspect. @justbecrazy, post your script, or you will just be driven crazy!

avatar image justbecrazy · Aug 10, 2011 at 02:33 AM 0
Share

Hi @aldonaletto and @overunity3d , Thank you vey much! I didn't use yield or StartCoroutine in any of my scripts, nor it's a mobile game. Here's my scirpt:


protected void Update () 
{
    Walk(targetNodeTr.position);
}
protected void Walk (Vector3 targetNode)
{
    float speed = Time.deltaTime * walkSpeed;
    Vector3 forward =myTransform.TransformDirection(Vector3.forward);
    myTransform.animation.Play("run");
    myTransform.LookAt(targetNode);
    myTransform.GetComponent《CharacterController》().$$anonymous$$ove(speed * forward);
}
protected void OnControllerColliderHit(ControllerColliderHit hit)
{
    if (hit.transform == targetNodeTr)
    {
        if (targetNodeTr.position == enemyEndPoint)
            Destroy(gameObject);
        else if (pathIndex < pathList.Count-2)
        {
            pathIndex++;
            GameObject targetNodeGO = GameObject.Find (pathList[pathIndex].ToString());
            targetNodeTr = targetNodeGO.transform;
        }
    }
}

Show more comments
avatar image
0

Answer by overunity3d · Aug 10, 2011 at 02:50 AM

Just an overview here:

myTransform.animation.Play("run");

You are doing this every update. Is the animation shorter than an update cycle? Is the 'run' cycle really necessary this quickly?

If the animation is several frames then you want to call this at a slower rate.

Hope I called this correctly.

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 justbecrazy · Aug 10, 2011 at 03:07 AM 0
Share

I deleted this line and it remains the same.

avatar image
0

Answer by overunity3d · Aug 10, 2011 at 03:13 AM

put a Debug.Log() in each if and else statement. The maniac activity should show up in the console. If it doesn't then you got bigger problems than Answers.unity.

Comment
Add comment · Show 2 · 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 justbecrazy · Aug 10, 2011 at 06:33 AM 0
Share

Rightnow I'm thinking about it's about the number of my enemies, because I changed this number to 1, and the FPS stays in 40+.

But it would be impossible to make my game only 1 enemy at a time. So do you guys have some ways to fix this?

Big thanks!!!

avatar image justbecrazy · Aug 10, 2011 at 06:51 AM 0
Share

But if I increased the enemies' number up to 5, the Fps started to fall down to lower than 20FPS.

avatar image
0

Answer by husbandofemily · Feb 25, 2012 at 06:36 PM

  • for changing the radius of the capsule. I only have one enemy in the scene, and the CharacterController only gets called if the Player is too close. The only things in the function are transform.LookAt (player) and SimpleMove (direction*Speed). Changing the radius of the CharacterController from 0.02 to 0.01 solves my slowdown issue (that only happens when you get too close to the NPC, and the chase function is called) HTH Ian

Comment
Add comment · 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
  • 1
  • 2
  • ›

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

7 People are following this question.

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

Related Questions

why does character controller accelerate off ledges? 1 Answer

How to I make my player push off of the ground? 0 Answers

How do i move CharacterController toward the direction its facing? 0 Answers

Is it possible to get transform.Translate() to move like CharacterController.Move()? 0 Answers

Fail with movedirection of Character Controller 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