check if variable has stopped increasing.

hello, I have a 2D game. I need it to check if the distance has stop increasing, therefore the 2D infinite running player stop moving because he got blocked by a blockage so the distance should be the same since no movement and therefore distance is not increasing.
P.S. since this is an infinite runner. I have no control over the movement of the player since he only runs to the left infinitely which means distance is constantly increasing until it is blocked so the distance should stop increasing and be the same distance over time. again how do I check that?

if ((gameObject.rigidbody.IsSleeping) && (rigidbody.velocity.magnitude == 0))

I suppose your player has a CharacterController conponiment it, if so you can can always check its velocity using this. Good thing about velocity is that you can check each axes individually or just use magnitude on all 3 of them to see if player is moving in any direction (if velocity.magnitude is 0 that the player is not moving).

I don’t think this is very difficult, you could have found the solution by yourself…

I will suppose the following script is attached to your character :

//C#

...

private float lastPosition = 0 ;
private float lastTime = 0 ;

public float Velocity
{
	get ;
	private set ;
}

void Start()
{
	lastTime = Time.time ;
}

void Update()
{
	if( Time.time != lastTime )
		Velocity = (lastPosition - transform.position.x) / (Time.time - lastTime);
		
	lastPosition = transform.position.x ;
	lastTime = Time.time ;
}


...

Then, run your background animation according to the velocity of your character, it will be smoother than stopping it directly if the character doesn’t move anymore.