How to make a sticky physic

Im Going to make a mob that sticks to a surface and when the player comes near it it unsticks and attacks and when it exits the players screen it sticks again, but im not sure how to make it stick in the 1st place

You want to have it use a once block to extract it’s X and Y positions and put then into numbers. When you want it to stick, have an always go into the numbers and the numbers go into a position block. When you want it to unstick, have it turn off the always block. When you want it to stick to it’s new location, have it extract new numbers and turn the always back on again.

That sounds complicated, but ill see what i can do