Movment stay consistent across multiple devices and framerates (510957)

Hello i have problem in my game movement that not stay consistent across multiple devices and frame rates .. i tested my game in galaxy grand with 4.1.2 OS and works fine however when i tested it in galaxy note 1 with 4.1.2 OS the movement goes crazy and unrealistic. here is the code:

var speed : float = 1.2;
    function Update () {
       if (Input.touchCount > 0  
         Input.GetTouch(0).phase == TouchPhase.Moved) {
 
         // Get movement of the finger since last frame
         var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
 
         // Move object across XY plane
         transform.Translate (touchDeltaPosition.x * Time.deltaTime * speed, 
                 touchDeltaPosition.y * Time.deltaTime * speed, 0,Space.World);
         }

since i used Time.deltaTime ? is this correct? so how i can make movement stay consistent across multiple devices and frame rates?

thx

I didn’t notice your problem at first because you are using Javascript and its god awful formatting for braces.

Using C# style formatting on the other hand:

var speed : float = 1.2;

function Update ()
{
    if (Input.touchCount > 0 
        Input.GetTouch(0).phase == TouchPhase.Moved)
    {
        // Get movement of the finger since last frame
        var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
     
        // Move object across XY plane
        transform.Translate (touchDeltaPosition.x * Time.deltaTime * speed,
            touchDeltaPosition.y * Time.deltaTime * speed, 0,Space.World);
    }
}

Makes it obvious to me that you’re only doing the movement code inside the if(touch phase == moved). I suppose I’d probably see it if I were used to Javascript style.

This means that you will get the Touch.deltaPosition for the movement for 1 single frame and move that amount * deltaTime (so like 1/50th of the actual movement depending on frame rate). Then next update your finger might not have moved so you get nothing.

The inconsistency you are observing just means that each device probably has slightly different ways of determining when a touch qualifies as moved as opposed to any of the other TouchPhase values.

What you probably need to do is something along the lines of:

var touchMovement : Vector2;

function Update ()
{
    if (Input.touchCount > 0 
        Input.GetTouch(0).phase == TouchPhase.Moved)
    {
        // Get movement of the finger since last frame
        var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;

        // Add it to the total movement
        touchMovement += touchDeltaPosition;
    }

    //If there is some movement to be done
    if(touchMovement != Vector2.zero)
    {
        //Figure out how much we want to move this frame
        var movementAmount : float = Mathf.Min(touchMovement.magnitude * speed, 10) * Time.deltaTime;//The 10 is the maximum speed you can move. You might want to put it into a public variable or something.
        var movement : Vector2 = touchMovement.normalized * movementAmount;//We want to move in the direction of the touchMovement, but the distance of movementAmount.

        // Move object across XY plane (using the movement we just calculated)
        // movementAmount already took speed and Time.deltaTime into account, so we don't want to do it again.
        transform.Translate (movement.x, movement.y, 0, Space.World);

        // Now that we've applied that movement, subtract it from the total movement that we still have to do.
        touchMovement -= movement;
    }
}

thanks for helping

however when i used your code the movement become heavy and one movement touch the object move and move and move with descending acceleration then at last stop … i need normal move with very light descending acceleration

thank you

If you change
touchMovement += touchDeltaPosition;
To something along the lines of
touchMovement += touchDeltaPosition * movementMultiplier;
Where movementMultiplier is maybe 0.1 or even less, then any touch movement will cause proportionally less movement overall, regardless of speed.

To change the actual speed, you will need to play around with your speed value and the 10 inside Mathf.Min() on line 19 of my code.