Do something after object has moved the stopped.

Hi !

So I’ve been at this for hours, and I really can’t find anything good. I’ve made a script that detects if the object with the script is rotating, and if it is rotating something happens. And then it resets. So if it starts rotating again, something happens again. Etc.

Now I’m trying to make a similar script, except I’d like it to be so something happens only when the object stops after rotating. And then resets itself, so that if the object starts rotating again and then stops, something happens again.

Hope that makes a little sense … ^^

Here’s what I’ve got !

	Vector3 prevPos;
	private bool hasPlayed = false;

	void Start(){
			prevPos = transform.rotation.eulerAngles;

		void CheckForMove(){
		if((prevPos != transform.rotation.eulerAngles) && (hasPlayed == false)){
				hasPlayed = true;
				prevPos = transform.rotation.eulerAngles;

Thanks in advance


You problem is that InvokeRepeating is a bit limiting.

I advise you to check Coroutines, and learn how to yield return StarCoroutine.
That way you can start one, and create custom loops, pause, wait, and iterate, all in the same function:

Try changing

prevPos != transform.rotation.eulerAngles


Vector3.Distance(prevPos, transform.rotation.eulerAngles) <= EPSILON

where EPSILON is a very small number. != might not work for Unity’s Vector classes.