I know there are probably a lot of different versions of these but none are in this studio so here you go. Just take the function from here and use it. Leave credit if you want but this was fairly simple and I'm sure many others have done it. The purple dot moves so you can see it works but you can of course remove it.