- Home /
Problem with counting front flips
I thought I have solved my problem to count a front flip but unfortunately that wasn't because I can't decrease it.
Here is the url from my last question about this: http://answers.unity3d.com/questions/1108288/problem-with-counting-front-flips.html
I want only count with +1 if the hero makes a full rotation from 360 - 0 and then decrease the count to 0 when the hero collides with a boost.
using UnityEngine;
using System.Collections;
public class Flip : MonoBehaviour {
public float flips = 0;
public float fliptest;
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 < -180f)
deltaRotation += 360f;
if (deltaRotation > 180f)
deltaRotation -= 360f;
if (deltaRotation < 0)
deltaRotation = 0;
WindupRotation += (deltaRotation);
flips = WindupRotation / 360;
//tried also this
if(flips >= fliptest)
{
fliptest++;
}
//
if (flips >= maxFlip) {
flips = maxFlip;
}
}
void OnTriggerEnter2D(Collider2D coll){
if (coll.gameObject.tag == "Boost") {
fliptest = 0;
}
}
}
I hope you guys can help me. Thanks a lot.
Comment
Answer by jmonasterio · Dec 11, 2015 at 01:56 PM
Line 42, add:
flips = 0;
The problem here is line 26:
flips = WindupRotation / 360;
so the value will never be 0.