Lag in Game making character jump

Hi Everyone,

My character is moving fine when there is limited things on the screen (a few spheres rotating), but when I add more, than 5 spheres or add a particle effect to one of them I get severe lag of the character when it moves (it jumps around the target position).

I was wondering if anybody could see anything in my code that could be changed to avoid the jumping or let me know a way to reduce the lag without taking objects out.

function CharacterControl()
{
    var count : int = iPhoneInput.touchCount;   
    if(state == ControlState.TrackingMove)
    {
        var touch : iPhoneTouch = iPhoneInput.GetTouch(0);

        if(touch.position.y > firingBorder && touch.position.y < 450)
        {

            var ray = cam.ScreenPointToRay( Vector3( touch.position.x, touch.position.y ) );
            var hit : RaycastHit;
            if( Physics.Raycast(ray, hit) )
            {
                var touchDist : float = (transform.position - hit.point).magnitude;
                if( touchDist > minimumDistanceToMove )
                {
                        targetLocation = hit.point;
                }
                moving = true;
            }
        }
        else
        {
            ResetControlState();    
        }

    }

    movement = Vector3.zero;
    rotate = Vector3.zero;

    if(state == ControlState.MovingCharacter)
    {
    if( moving )
    {
        // Move towards the target location
        movement = targetLocation - thisTransform.position;
        movement.y=0;
        movement.z=0;

        var dist : float = movement.magnitude;
        if(movement.x < 0)
        {
            rotate = Vector3(0,0,25);
        }

        if(movement.x > 0)
        {
            rotate = Vector3(0,0,-25);
        }
        if( dist < 1 )
        {
            moving = false;
            ResetControlState();
            rotate = -rotate;
        }
        else
        {
            movement = movement.normalized * speed;
        }
    }

    movement += velocity;       
    movement += Physics.gravity;
    movement *= Time.deltaTime;

    // Actually move the character
    character.Move( movement );
    character.transform.Rotate(rotate);
    velocity = Vector3.zero;
    }
}

Thanks

Chris

Couple things:

  1. If the particle effects are the only things using physics you can lower fixed time right down, something like 0.6 or higher, this wont work if your character moves with physics though1.
  2. Lower draw calls, if you have several objects in the scene you can make them share a single texture to increase the amount of batching going on. Just stick all your textures onto a single huge texture
  3. Similar to item 2, reduce memory usage by reducing texture size and quality, generally for 3D objects 256 or even 128 will do
  4. Reduce mesh size, you can model all the objects in a room into a single mesh and then you can remove all the reverse side polys. Also consider using culling if your character regularly moves between rooms, by setting objects to static and creating a few bounding zones you can cull all the objects in a room you're not in speed things up.
  5. Use fewer particles, you've said you didn't want to remove them but you can usually pull off the same effect with fewer particles by animating them or using a single animated texture instead of complex particles