Checking when the player is stopped, without velocity?

My game is an endless runner, so velocity is a constant. But I need to find out when the player has stopped due to colliding with a platform. I cannot check for when velocity is very small, because velocity is constant, even when the player is halted by a platform. But I also cannot check for collision with a platform, because then what I want to happen will be triggered every time the player collides with a platform.

It has to be something with the player’s position, right? Can someone point me in the right direction please? I’ve been at this for hours.

Endless runners normally use you leaving the screenspace to determine death if that’s what your trying to do.

To do that a simple bounds check will work.

if your just wanting to know if someone is stuck on a wall as it were for whatever reason there are a few ways.

firstly oncollsionstay()

not on collision enter or on collision exit but on collision stay.

you can simply run a timer -= time.fixedtime or whatever and every physics update they stay in contact the timer will count down, if timer <= 0 (do something).
This means you can just say, if someone stays in contact with a wall for 5 seconds or whatever, something happens.

as for using position, you could use position to determine if your starting to go backwards basically and you could even do something where you store the current frames position in global space as lastpos, then next frame you compare lastXpos - screen movement per frame and now if someone isn’t moving, there position will be just that. if your “standing still” on a moving screen, your position will be in one frame, the position you were in the last frame but negative at least on the X axis the value at which the screen is moving right.

No problem, you’ll want to check the player’s previous position against their current position. If the distance is the same or minimal (using a tolerance), they’re not moving. When the player moves, set their position to lastPos. Then, check the difference of the x value between the lastPos and curPos variables…

Here is a sample of how it could be done:

    public bool     moving;
    public float tolerance;
    public Vector2 prevPos;
    public Vector2 curPos;

    private Transform t;

    void Awake()
    {
        t = transform;
    }

    void Update()
    {
        // Move the game object however you set it up
        // This line is where you set the velocity to move your game object.

        // Moving? (along the horizontal axis)
        if ( t.position.x - tolerance > prevPos.x )
        {
            // Set last position
            prevPos = t.position;
        }
        else
        {
            // We're not moving
            moving = false;
        }
    }

Alternatively, you can get the distance between both positions but since your game is an endless runner, you only need to check against one axis…