Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to detect a full backflip/frontflip of an object

Discussion in 'Scripting' started by Bram280, Aug 8, 2023.

  1. Bram280

    Bram280

    Joined:
    Dec 1, 2019
    Posts:
    5
    How would one detect a full backflip/frontflip of an object on the x-axis, y-axis, z-axis seperately. With a full backflip the object should not be able to flip back and count as a flip.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    Here was my nod yes / no gesture recognizer:



    Source linked in video comments.

    You could use the same technique to observe your player and mark each portion of a flip in sequence, and if you complete it, consider the flip done.
     
    Yoreki likes this.
  3. Bram280

    Bram280

    Joined:
    Dec 1, 2019
    Posts:
    5
    The way I got it to work is by just keeping track of the input instead of the rotation.
    Code (CSharp):
    1.    
    2.     Vector2 rotationInput;
    3.     float totalRotation = 0f;
    4.     [SerializeField] float rotationSpeed = 360f;
    5.  
    6.     // Update is called once per frame
    7.     void Update()
    8.     {
    9.         transform.Rotate(new Vector3(rotationInput.y, rotationInput.x, 0f) * rotationSpeed * Time.deltaTime, Space.World);
    10.         totalRotation += rotationInput.y * Time.deltaTime * rotationSpeed;
    11.         if (totalRotation <= -360f)
    12.         {
    13.             totalRotation += 360f;
    14.             Debug.Log("flipped");
    15.         } else if (totalRotation >= 360f)
    16.         {
    17.             totalRotation -= 360f;
    18.             Debug.Log("flipped");
    19.         }
    20.     }
    21.  
    22.     public void OnRotation(InputValue value)
    23.     {
    24.         rotationInput = value.Get<Vector2>();
    25.     }
     
    Kurt-Dekker likes this.