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