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: https://www.youtube.com/watch?v=MAgaGIxzGs4
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.
Comment
Best Answer
Answer by Bunny83 · Dec 06, 2015 at 04:14 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220612051557im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why my counting method is stucked on the beginning? 1 Answer
wrong flip 0 Answers
Calculate UP Distance Displacement for 3D Infinity Runner Game 4 Answers
need help to implement a function in the assets flip book 0 Answers
Score system not working 1 Answer