- Home /
How do I make my FPSController more responsive and smooth (it's very sluggish)?
Hello I have an FPSController script and it plays fine, but it is very sluggish and when it comes into contact with any that has physics/collision like a wall or box it kind of just gets "caught" in the collision rather than smoothly reacting to it. I've tried other FPS Controllers and none have this problem from what I've seen, it gets almost unmoveable when it comes into contact with an exact collision mesh. When it comes into contact with a box collider mesh it either reacts by getting stuck or being very sluggish on impact for a few seconds making the player have to remove himself from the wall before he can go back on his way. I'd like any tips, pointers, or any explanations as to why this is happening.
Here's my FPSController Script (I wanted to paste it but it was very long so I used an external link)
Bro, nobody is going to look through 1000 lines of code just to see how to make your script better. To me, it looks as if you downloaded this script. So I recommend looking through all the code, taking out the parts you don't need and then work on optimization yourself. Experiment. It's the best way to learn.
Some tips as to why this maybe happening: 1. Too many smoothing variables / functions 2. Too much math calculations 3. Code is running at improper frames (example, every other frame)
Try it yourself and take out parts. If you don't want to, download another script from the Unity Wiki site or just use the one that comes with Unity. The FPS controller from the sample assets is really nice.
Answer by Jeff-Kesselman · Jun 07, 2014 at 10:59 PM
If you a re running in pro then the first thing you should do is run the profiler and see whats really costing you time.
If you don't have that, tuning this will be a lot harder. Some things to look for:
Update code. Update code runs every frame. You should be doing as little work in Update (or fixed Update) as possible. As much s possible you want to b even driven. Same is true for FixedUpdate.
Debug logging. Debug logging is surpassingly expensive. if you a re spitting out a lot of debug log info to the consoe, try commenting it out.
CollisionStay methods. This gets back to begin event driven rather then polling. Try do do as much work as possible on the enter and exit rather then on every stay frame
Well I didnt actually mean performance wise, because i am getting near 300 fps on a pretty old card. What I meant was the actually fps controller, but thank you for the extra tips as I may have this problem in the future.