<commit_before>﻿using UnityEngine;
using System.Collections;
using Leap;
using Leap.Unity;

public class FlightController : MonoBehaviour
{
	Controller flyController;
	GestureRecogniser gestureRecogniser;
	public GameObject vehicle;
	float rotateAngleX;
	float rotateAngleZ;
	float rateOfChange = 0.00058f;
	float topRot = 1.0f;
	float topSpeed = 16.0f;
	float speed = 0.0f;
	float acceleration = 0.07f;
	float handling = 40.0f;
	Vector3 velocity = new Vector3(0.0f,0.0f,0.0f);

	// Use this for initialization
	void Start()
	{
		//Initalise flight controller
		flyController = new Controller();
		gestureRecogniser = GetComponent<GestureRecogniser>(); 
		rotateAngleX = 0.0f;
		rotateAngleZ = 0.0f;


	}


	void Update()
	{
		System.Collections.Generic.List<Leap.Hand> hands = gestureRecogniser.getFrameHands();
		string current_gesture = gestureRecogniser.Recognise(hands[1]);
		string for_ui = gestureRecogniser.Recognise(hands[0]);
		if (hands.Count == 2) {
			Leap.Hand r_hand = hands [1];
			if (r_hand != null) {

				float RollAngle = r_hand.PalmNormal.Roll;
				float PitchAngle = r_hand.Direction.Pitch;
				Tilt (RollAngle);
				Rise (PitchAngle);
			}

			velocity = vehicle.transform.forward * speed * Time.deltaTime;
			vehicle.transform.position += velocity;
			Debug.Log ("Speed :" + speed);
			if (speed <= topSpeed) {
				Debug.Log ("Making it to increase speed");
				speed += acceleration;
			}
		} 


	}

	bool Tilt(float Roll)
	{

		if (Roll > 0.0f) {
			if (Roll > 1.0f && Roll < 2.0f) {
				Quaternion targetRotation = Quaternion.AngleAxis((1.0f * Mathf.Sign (Roll)), Vector3.up);
				vehicle.transform.rotation = Quaternion.Slerp(vehicle.transform.rotation , vehicle.transform.rotation *= targetRotation, handling * Time.deltaTime);
				return true;
			}
		} else {
			if(Roll > -2.4f && Roll < -1.5f){
				Quaternion targetRotation = Quaternion.AngleAxis((1.0f * Mathf.Sign (Roll)), Vector3.up);
				vehicle.transform.rotation = Quaternion.Slerp(vehicle.transform.rotation , vehicle.transform.rotation *= targetRotation, handling * Time.deltaTime);
				return true;
			}

		}

		return false;
	}
	void Rise(float Pitch)
	{
		float direction = 1.0f;
		if (Pitch > 1.6f) {
			direction *= -1;
			Quaternion targetQuat = Quaternion.AngleAxis (direction, Vector3.left);
			vehicle.transform.rotation = Quaternion.Slerp(vehicle.transform.rotation, vehicle.transform.rotation *= targetQuat, handling * Time.deltaTime);
		} else if (Pitch < 0.5f) {
			Quaternion targetQuat = Quaternion.AngleAxis (direction, Vector3.left);
			vehicle.transform.rotation = Quaternion.Slerp(vehicle.transform.rotation, vehicle.transform.rotation *= targetQuat, handling * Time.deltaTime);
		}

	}


}
<commit_msg>Added drifting/slippery flight<commit_after>﻿using UnityEngine;
using System.Collections;
using Leap;
using Leap.Unity;

public class FlightController : MonoBehaviour
{
	Controller flyController;
	GestureRecogniser gestureRecogniser;
	public GameObject vehicle;
	float rotateAngleX;
	float rotateAngleZ;
	float rateOfChange = 0.00058f;
	float topRot = 1.0f;
	float currentMaxSpeed = 20.0f;
	float topSpeed = 20.0f;
	float nitrosSpeed;
	float speed = 0.0f;
	float acceleration = 0.07f;
	float handling = 40.0f;
	Vector3 velocity = new Vector3(0.0f,0.0f,0.0f);

	// Use this for initialization
	void Start()
	{
		//Initalise flight controller
		flyController = new Controller();
		nitrosSpeed = topSpeed * 2.0f;
		gestureRecogniser = GetComponent<GestureRecogniser>(); 
		rotateAngleX = 0.0f;
		rotateAngleZ = 0.0f;


	}


	void Update()
	{
		System.Collections.Generic.List<Leap.Hand> hands = gestureRecogniser.getFrameHands();
		string current_gesture = gestureRecogniser.Recognise(hands[1]);
		string for_ui = gestureRecogniser.Recognise(hands[0]);
		if (hands.Count == 2) {
			Leap.Hand r_hand = hands [1];

			if (for_ui == "FIST") {
				topSpeed = nitrosSpeed;
			} else {
				topSpeed = currentMaxSpeed;
			}
			if (r_hand != null) {

				float RollAngle = r_hand.PalmNormal.Roll;
				float PitchAngle = r_hand.Direction.Pitch;
				Tilt (RollAngle);
				Rise (PitchAngle);
			}
			//Added slipperiness to flight, to make it more natural
			velocity = (velocity.normalized + (vehicle.transform.forward) / (handling * 1.5f) ) * speed * Time.deltaTime;
			vehicle.transform.position += velocity;
			Debug.Log ("Speed :" + speed);
			if (speed <= topSpeed) {
				Debug.Log ("Making it to increase speed");
				speed += acceleration;
			} else {
				speed *= .99f;
			}
		} 



	}

	bool Tilt(float Roll)
	{

		if (Roll > 0.0f) {
			if (Roll > 1.0f && Roll < 2.0f) {
				Quaternion targetRotation = Quaternion.AngleAxis((1.0f * Mathf.Sign (Roll)), Vector3.up);
				vehicle.transform.rotation = Quaternion.Slerp(vehicle.transform.rotation , vehicle.transform.rotation *= targetRotation, handling * Time.deltaTime);
				return true;
			}
		} else {
			if(Roll > -2.4f && Roll < -1.5f){
				Quaternion targetRotation = Quaternion.AngleAxis((1.0f * Mathf.Sign (Roll)), Vector3.up);
				vehicle.transform.rotation = Quaternion.Slerp(vehicle.transform.rotation , vehicle.transform.rotation *= targetRotation, handling * Time.deltaTime);
				return true;
			}

		}

		return false;
	}
	void Rise(float Pitch)
	{
		float direction = 1.0f;
		if (Pitch > 1.6f) {
			direction *= -1;
			Quaternion targetQuat = Quaternion.AngleAxis (direction, Vector3.left);
			vehicle.transform.rotation = Quaternion.Slerp(vehicle.transform.rotation, vehicle.transform.rotation *= targetQuat, handling * Time.deltaTime);
		} else if (Pitch < 0.5f) {
			Quaternion targetQuat = Quaternion.AngleAxis (direction, Vector3.left);
			vehicle.transform.rotation = Quaternion.Slerp(vehicle.transform.rotation, vehicle.transform.rotation *= targetQuat, handling * Time.deltaTime);
		}

	}


}

{'fraction_non_alphanumeric': 0.12352737352737353, 'fraction_numerical': 0.02234927234927235, 'mean_word_length': 3.802828618968386, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4613784', 'n_tokens_mistral': 2273, 'n_tokens_neox': 1931, 'n_words': 427}