Linear laggy/stuttery movement


I have been going through the forum to check if some one had an answer to my problem. I am implementing a small 2d game. When some one touch the screen, the main object moving to that position in a linear way.

I used DOTween and iTween to do it at the beginning, but I noticed a jump while moving when using either of them. Basically it looks like the position is being updated more times than the GPU can take it to show it smoothly. (and I’m pretty sure it’s the issue considering what I have read on the forum ).

My issue is now I have tried attaching a rigidbody2d to my object to use Velocity and so the position updates aren’t up to me, but it’s even worse.
My update algo is :

// Calculate how much to translate of

m_movement.x = m_direction.x * Time.smoothDeltaTime * SPEED;
m_movement.y = m_direction.y * Time.smoothDeltaTime * SPEED;

// Calculate the next position
m_nextPosition.x = transform.position.x + m_movement.x;
m_nextPosition.y = transform.position.y + m_movement.y;

// Calculate the new distance between the point touched on screen and the object
float currentDistance = Vector2.Distance (new Vector2 (m_nextPosition.x, m_nextPosition.y), m_targetPosition);

// we have reached the target position or the next position is going to be slightly further away
// Then just stop updating the position and set the new position as the target position
if (currentDistance == 0 || currentDistance > m_prevDistance)
	m_state = STATE.IDLE;
	m_prevDistance = -1;
	transform.position = m_targetPosition;
	m_prevDistance = 0;
// Otherwise move the object and update the distance between target position and current position
	m_prevDistance = currentDistance;

On MAC, it obviously doesn’t go wrong, but on iPhone4, Samsung mini-s4 and HTC M8, I have some stuttery/jump/laggy movement…Any idea how to sort that out ?

I tried FixedUpdate, Time.deltaTime, Time.fixedDelta. Using rigidbody2d as I said, clamping the Time, to make sure it’s not greater than 0.03 or making sure the range is between 0.02 and 0.04 , but none stops the laggy altogether.

Any idea guys ?

I can add a video if needed.


Have you tried LateUpdate ?

EDIT : Just realised you were using a Rigidbody. You shouldn’t update its transform, but rather move it using setVelocity.