Problem with counting front flips

Hi,

I have a problem with counting front flips. The problem here is when the hero makes a back flip it still counts and I don’t want it.

Here’s a video of it:


Script:

using UnityEngine;
using System.Collections;

public class Flip : MonoBehaviour {

	public float flips = 0;
	public float maxFlip = 12;
	public float deltaRotation = 0;
	public float currentRotation = 0;
	public float WindupRotation = 0;

	void Update () {
		deltaRotation = (currentRotation - transform.eulerAngles.z);
		currentRotation = transform.eulerAngles.z;
		if (deltaRotation <= -300) 
			deltaRotation += 360;
		if (deltaRotation < 0)
			deltaRotation = 0;
		
		WindupRotation += (deltaRotation);
		
		flips = WindupRotation / 360;
		if (flips >= maxFlip) {
			flips = maxFlip;
		}
	}
}

Is there a way to prevent it? Thanks for your help.

You only warp your delta angle in one direction. Try:

     if (deltaRotation < -180f) 
         deltaRotation += 360f;
     if (deltaRotation > 180f) 
         deltaRotation -= 360f;
     if (deltaRotation < 0)
         deltaRotation = 0;

This way the delta rotation is always in the range -180 to 180, no matter in which direction it wraps around.