Car Trick System -think cruisin usa

Hey I’m making a game where you get points for doing 360’s and 180’s and such.

I’m trying to calculate how many turns the vehicle does when a wheel colider is no longer grounded.

I have no clue on using quaternion math so can anyone off some suggestions?

I’ve already got a basic algorithm working but it has flaws like if the vehicle somehow changes direction, it wouldn’t know. I’m looking for an elegent way of doing this.

function DoTricks() {
	if( StartRot.x == 0 ) {
		StartRot.x = (int)transform.localEulerAngles.x;
		StartRot.y = (int)transform.localEulerAngles.y;
		StartRot.z = (int)transform.localEulerAngles.z;
	}
	
	var CurRot : Vector3;
	CurRot.x = (int)transform.localEulerAngles.x;
	CurRot.y = (int)transform.localEulerAngles.y;
	CurRot.z = (int)transform.localEulerAngles.z;
	
	if( (int) CurRot.x > (int) LastRot.x )
		RotDegress.x++;
	else if( (int) CurRot.x < (int) LastRot.x )
		RotDegress.x--;
		
	if( (int) CurRot.y > (int) LastRot.y )
		RotDegress.y++;
	else if( (int) CurRot.y < (int) LastRot.y )
		RotDegress.y--;
		
	if( (int) CurRot.z > (int) LastRot.z )
		RotDegress.z++;
	else if( (int) CurRot.z < (int) LastRot.z )
		RotDegress.z--;
		
	Rotations.x = RotDegress.x / 360;
	Rotations.y = RotDegress.y / 360;
	Rotations.z = RotDegress.z / 360;
	
	
	LastRot.x = (int)transform.localEulerAngles.x;
	LastRot.y = (int)transform.localEulerAngles.y;
	LastRot.z = (int)transform.localEulerAngles.z;
}

It’s mess and at the moment and horribly inacurate.
Can anyone offer a better way?

and the casting (int) doesn’t seem to work because in the inspector window it still shows 5 or 6 decimal places.

Basically I just want to convert localEulerAngles or eulerAngles to degrees, because after eulerAngles hits 360, it jumps back to 0, when this happens I just want to keep counting to 361 so I can calculate 1080’s and such.

Thanks!

Quaternions don’t have any way of recording how many turns have been made, so when the angle goes beyond 360º, it wraps back around to zero. The only way to detect how many times an object has turned is to keep sampling the rotation Euler angle at regular intervals and have a variable that accumulates every full turn. Basically, you need to detect when the angle goes from something near 360º to something near zero and add 360 to the accumulator when this happens.