How to sync the velocity of a rigidbody with a texture offset?

Hi!
I’m creating a 2d endless runner game, where my character climbs a tower jumping from stone to stone. I wrote a code that repeats the tower texture and increase its offset velocity as you keep playing, and a code that keeps spawning the stones on the tower, but I couldn’t create a code that moves the stones from top to bottom at the same velocity of the tower, it’s desynchronized, I need to sync them to look like the stones are fixed to the tower (I’m using a rigidbody on the stones prefabs).

The script that is attached to the tower:

public float speed = 0.2f;
    public float speedAux = 0f;
   
    public Vector2 offset;
    Renderer rend;

    private void Awake()
    {
        rend = GetComponent<Renderer>();
    }

  
    void FixedUpdate()
    {
        offset = new Vector2 (0, Time.time * speed);
        rend.material.mainTextureOffset = offset;
        speedAux += 0.00001f;
        if(speed < 0.5f){
            speed += 0.00001f;
        }
        else if(speedAux > 0.5f && speed < 0.7f){
            speed += 0.00001f;
        }
    }

I’ve tried a lot of things but couldn’t achieve the result I need, can somebody help me with that?

You will need the following values:

  1. the linear worldspace distance that this texture is stretched over

  2. the position of a given stone… by definition a single texture cannot track multiple stones, so you have to rely on the fact that all stones descend at the same rate

  3. each frame check how far that stone moves (you can make a ghost stone that has no visible part on it, and keep recycling it back to the top)

  4. scale down the distance the stone moved this frame by dividing by the value in #1 above (total length of texture)

  5. adjust the UV offset of that texture by that distance.

  6. set that UV offset into the texture as you did above.

This will work as long as the UV scale is 1,1. If it is different you will have to divide out the movement by that scale value.

Thanks!!! I will try this out!