smooth transitions for Rigibodies objects on iPhone and iPad

Hi I have been trying to get smooth transitions for my objects with Rigibodies on the iPhone. I have tried making modification in the Time Manager and I got stuck. Right now everything seems to run choppy...

I also have a hero in my game and he runs choppy left and right too. Here's the movement part of the script:

private var moveDirection = Vector3.zero;
function FixedUpdate()
{
    MoveMent();
}

function MoveMent()
{
    var controller: CharacterController = myTransform.GetComponent(CharacterController);
    moveDirection = Vector3.zero;
    fTravelDist = fTravelSpeed * Time.deltaTime; 
    if(sState == "MoveRight")
    {
        moveDirection = Vector3(fTravelDist,0,0);
    }
    else if(sState == "MoveLeft")
    {
        moveDirection = Vector3(fTravelDist*-1,0,0);    
    }
    controller.Move(moveDirection);
}

Thanks again for all the help. I am learning so much about unity and enjoying it the whole way along.

Character Controllers are not considered rigidbodies. I do not know if you have a rigid body on your object, but you should remove one if you have both.

Based on your movement script, the only problem I see is that you are calling your function from FixedUpdate() when you should be calling it from Update for 2 reasons:

  1. Update gives better performance than fixedUpdate hence FixedUpdate should only be used if you are using a rigidbody.

  2. You are multiplying your Speed by Time.deltaTime. Time.deltaTime is 1/FPS so you want a function that is called every frame such as Update(). Since Fixed Update is called a constant rate and Time.deltaTime varies, that is probably why you are getting stuttering. You could use Time.fixedDeltaTime if you insist on using FixedUpdate();


A few more random points to help your performance.

  • You should cache your CharacterController so that you do not have to find it every frame which is expensive. (see below)

  • You could inline your entire movement function. The compiler might do it anyway for you, but unnecessary function calls are not good. You might want to do some tests to see if there is any difference.


private var moveDirection = Vector3.zero;
private var controller : CharacterController;

function Start () {
     controller = GetComponent(CharacterController);
     //Cache the controller
}

function FixedUpdate()
{
    MoveMent();
}

function MoveMent()
{

    moveDirection = Vector3.zero;
    fTravelDist = fTravelSpeed * Time.deltaTime; 
    if(sState == "MoveRight")
    {
        moveDirection = Vector3(fTravelDist,0,0);
    }
    else if(sState == "MoveLeft")
    {
        moveDirection = Vector3(fTravelDist*-1,0,0);    
    }
    controller.Move(moveDirection);
}