# How to check car has rotated a complete rotation i.e 360. so I can add 1 int value to score.. https://www.youtube.com/watch?v=9Ztd1XXmUGI like in this game Thanks.

How to check car has rotated a complete rotation i.e 360. so I can add 1 int value to score..

Vector3 strtAngle;
Vector3 ChangedAngle;
int ang;

``````float z_angle;

private void Start()
{
///////////////
strtAngle = new Vector3(0, 0, transform.rotation.eulerAngles.z);

ang = 0;

}
private void Update()
{
z_angle = transform.rotation.eulerAngles.z;
ChangedAngle = new Vector3(0, 0, transform.rotation.eulerAngles.z);

Debug.Log("finalAngle" +ChangedAngle);

float angle = Vector3.Angle(strtAngle, ChangedAngle);
Debug.Log("angle: " + angle);

// Vector3 targetDir = ChangedAngle - transform.chan;
// float angle = Vector3.Angle(targetDir, transform.forward);

if (angle > 350f)
}﻿
``````

I think you are almost there. One thing, that will depend on how you want it, but I think you need to decide. Which is when the player can start spinning for points, which I think should be when leaving/not touching the track anymore (ie in air). I assume this is done by tagging ground as ‘ground’

``````[SerializeField]
float previousAngle, currentAngle, flipAngle;
[SerializeField]
bool inAir;
[SerializeField]
int _360s = 0;

private void Update()
{
if (inAir)
{
currentAngle = transform.eulerAngles.z;
// Calculate the angle the bike has turned since the last frame and add to total rotation for this jump
flipAngle += Mathf.DeltaAngle(currentAngle, previousAngle);

previousAngle = currentAngle;
}
}

void OnCollisionExit(Collision collisionInfo)
{
Debug.Log("No longer in contact with " + collisionInfo.transform.name);
if (collisionInfo.gameObject.tag == "Ground") // you need to determine what counts as track/ground
{
inAir = true;
_360s = 0;
flipAngle = 0;
previousAngle = transform.eulerAngles.z;
}
}

void OnCollisionEnter(Collision collisionInfo)
{
Debug.Log("Now contact with " + collisionInfo.transform.name);
if (collisionInfo.gameObject.tag == "Ground") // you need to determine what counts as track/ground
{
inAir = false;
// You can decrease this ever so slightly, to accomodate for slopes. Or just add floats that account for take-off and landing-slopes
_360s = (int)flipAngle / 360;
if (_360s > 0)
Debug.Log("You did " + _360s + " front flips!!!");
else if (_360s < 0)
Debug.Log("You did " + _360s + " back flips!!!");
}
}
``````

Thanks for fast reply, I wrote the same but in the update function the condition not checking and more this function cannot catch the condition value

if (Mathf.Abs(strtAngle - currentAngle) > 360)
{
// no of rotations (count here)
}

the value 360 is cant catch it. may be bcz of FPS

OnCollisionEnter(Collision collisionInfo) & void OnCollisionExit(Collision collisionInfo)
some times inAir not getting true after colliding ground so i used raycast to check ground.

void IsGrounded()
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, 1.0f, lineLayer);
// Debug.Log(“Collided with:” + hit.collider.name);
if (hit.collider != null && hit.collider.tag == “Ground”)
{
isGrounded = true;
// Debug.Log(“GROUNDED”);
}
else
{
isGrounded = false;
Debug.Log(" not GROUNDED");
}
Debug.DrawRay(transform.position, Vector3.down,Color.green);
}
How to make RIDER in Unity (Livestream) - YouTube