- Home /
Frames per second rapidly dropping?
In the game I'm making there's 5 instanciaters which will birth 2 objects a piece over the life of the level. The objects themselves are baskets with 3 balloons attached and have about 100 faces or less, as the baskets move across the screen you can fire arrows at them which if don't hit the balloons will be deactivated once they hit a collider and the baskets and leftover balloons are deactivated once they hit a collider outside of the view. The game runs smooth but starts to run slower. If i reload the game by refreshing the browser it runs perfect again at first. The only Update Functions in the game are attached to the bow and arrow for aiming reasons and on the baskets to move them across the screen but those are deactivated once they cross the screen. I have the fixed timestep set at .01 because .02 lets the arrows fly trough the balloons without destroying them, but even at .02 the game still slows at the same time. First i thought it was an issue with instantiating so i worked around that. Then I thought maybe i had too many faces so I removed everything except 3 cylinders that do nothing and had the same results. Any reason the fps would be dropping like that? Thanks
I think you'll need to give more detail about what's going on in your game. From what you've described, there's nothing that Unity should struggle with, but you haven't given us much to go on!
Answer by ThumbStorm · Feb 15, 2010 at 09:20 PM
I think I've figured out the problem. I have an invisible cube in the center for the bow and arrow look at for aiming. The cube has this script : var screenSpace; var offset;
function Start () {
screenSpace = Camera.main.WorldToScreenPoint(transform.position);
offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z));
}
function Update () {
var cubeScreenSpace = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);
var cubePosition = Camera.main.ScreenToWorldPoint(cubeScreenSpace) + offset;
transform.position = cubePosition;
}
Then the bow & arrow has a modified smoothLookAt Script:
var target : Transform; var damping = 6.0; var smooth = true; static var Gpause : boolean = true; @script AddComponentMenu("Camera-Control/Smooth Look At")
function LateUpdate () { if (Gpause == false) { if (target) { if (smooth) { // Look at and dampen the rotation var rotation = Quaternion.LookRotation(target.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); } else { // Just lookat transform.LookAt(target); } } }
}
function Start () { // Make the rigid body not change rotation if (rigidbody) rigidbody.freezeRotation = true; }
Is there a way to do this so it doesn't slow the game because I like the effect it creates. Thanks
I'm a moron! There was a script being added every update to an object.