- Home /
Low FPS while playing animations.
var anim : String;
var AnimationSource = gameObject;
function OnTriggerStay()
{
if(Input.GetKey("e"))
animation.Play("AirlockOpen", PlayMode.StopAll);
}
Hello,there. I have about 4 Doors in my scene they open like airlock doors (one part to the left one to the right) they are moved by an animation.
So far so good, the code works but when i activate about 3 door at once the game´s Fps drop to an unplayable state. While playing about three animations i get like 10-15 Frames. Is this normal? the Doors are very low poly. What am i doing wrong? Is it because of the animations? Any help appreciated.
PS: Im from Austria so my english isnt the best.
Try building your project and run it, sometimes lag is just in the editor.
Have you read the documentation on OnTriggerStay? Especially the part about getting called every physics update when a collider is touching the trigger. Perhaps that's the reason? $$anonymous$$aybe you should try OnTriggerEnter ins$$anonymous$$d.
Answer by Sindorej · Dec 14, 2013 at 07:33 PM
It is because when you call GetKey it gets called while the key is pressed. You should replace it with GetKeyDown. Small notice : instead of "e" use KeyCode
Ok i changed it to Get$$anonymous$$eyDown. Still works but the FPS are not any better. I also tried Building the game but its still not better. btw what do you mean by $$anonymous$$eyCode?
You can still move the door by applying a force to it, if it is an object with a collider and physics material. Check out that. This needs to have a rigidbody component.
rigidbody.AddRelativeForce(0f,0f,thrust,Force$$anonymous$$ode.Acceleration
also check
http://docs.unity3d.com/Documentation/$$anonymous$$anual/Physics.html
By $$anonymous$$eyCode i mean
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space)
Ok thanks. Im going to try that tomorrow. So i guess animations are the wrong way to go when opening doors or stuff like that.
Check this one out
http://unity3d.com/learn/tutorials/modules/beginner/physics/joints
He blasts the door using a joint as a hinge
Ok i found out what causes the FPS drop. I tried a few different things. 1.) changing the OnTriggerStay to OnTriggerEnter didn't do much for my FPS. Also with OnTriggerEnter i couldn't implement my press e to open and i had to make it open automatic.
2.)At first i had only one door in my scene and i set the collider to mesh. So when i duplicated my doors everyone had a mesh collider. I changed that and now i have much better FPS.
3.)I still need to try out the "physics" way of doing this ins$$anonymous$$d of animations.
Thanks for the help everyone.
Answer by TheHoboCoder · Dec 14, 2013 at 07:19 PM
You could try to use GetKeyDown instead of GetKey. Don't know if it changes anything but at least it only runs it once.