- Home /

# 2d detect 360 (backflip) rotation on z axis?

Hi,

So I am making a 2d car game and am trying to implement scoring points based on the amount of backflips completed. I am not sure how to calculate (once the car has left the ground) if it has completed a full 360 degree turn anti-clockwise to then score a point. Does anyone know how I detect this?

Any help is greatly appreciated, thanks.

**Answer** by Teravisor
·
Jan 26, 2016 at 08:40 PM

It's so simple... I don't know how you didn't thought of that...

You can start counting it only when you change state from on-ground to airborne.

Each frame add to some variable that counts how much you turned while airborne.

Until you're out of airborne state. Then check which angle you've changed since 1. and score a point if you did do >=360 degree turn. Stop counting.

In order to check exactly counterclockwise and not just any angle, you need a simple math: angle between Vector(1,0) and Vector(x,y) is `Mathf.Atan2(y,x);`

(returns from -180 to 180 degrees in radians so multiply by Mathf.Rad2Deg and check when it goes from -179 to +179 or just use RigidBody2D.inertia) then subtract previous value of same angle to find angle change. Positive will be counterclockwise and negative will be clockwise.

How do I count how much I have turned? Could you give an example of it?

Thanks for the answer though, it answers most of my queries, thanks @Teravisor

One potential approach would be to save your previous rotation on a frame, then compare it with your new rotation at the end of the current frame. For that, you could use something like:

```
Quaternion lastRotation = transform.rotation;
// Apply rotational changes
Quaternion rotationOnFrame = Quaternion.Angle(lastRotation, transform.rotation);
```

Or, in the case of using the physics engine, the process can be inverted, where the last frame's rotation is grabbed at the end of the script and the difference is compared before changing its value again.

Sorry for being a pain, but I am still confused. So do i set the `lastRotation`

when I leave the ground and `rotationOnFrame`

when I land again? Also, Quaternion.Angle is a float, not a Quaternion. How do I know the car has gone all the way round, and what if it goes more than 360 degrees? Thanks for the help @Eno Khaon

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Why this flip rotation only works for parent, but not child? 0 Answers

car suspension and torque help 0 Answers

Flip the player with arm rotation 2 Answers

Flip over an object (smooth transition) 3 Answers

2D spaceship rotation 0 Answers