void FixedUpdate() { Debug.Log("Start HM"); RaycastHit hit; //Vertical thrusters foreach (Transform thruster in Thrusters) { // TODO :: add some sort of control for flipping upside down, or change the // angle at which the hover opperates, or use multiple types of raycasts etc. // basically any way to make the care not freak out when going around curves. if (Physics.Raycast(thruster.position, -thruster.up, out hit, HoverHeight, BodyLayerMask)) { //NOTE:: I added the square to the scalar because it was sometimes tipping over. CarRigidBody.AddForceAtPosition(Vector3.up * HoverForce * Mathf.Pow((1.0f - (hit.distance / HoverHeight)), 2), thruster.position); //TODO:: make this more efficient, no need to recalculate on each thrustor.... //CarRigidBody.drag = 4; //carRigidBody.mass = 500; } // ADD suction force - doesn't make physics nice... (my opinion) //else if (Physics.Raycast(thruster.position, -thruster.up, out hit, HoverHeight + 1, BodyLayerMask)) //{ // CarRigidBody.AddForceAtPosition( - Vector3.up * suctionForce, thruster.position); //} else { //NOTE:: this is a hack, should rather examin the gravity carefully. //CarRigidBody.AddForceAtPosition(Vector3.down * AirTimeGravity, thruster.position); //CarRigidBody.drag = 0; //carRigidBody.mass = 8000; } } if (!Physics.Raycast(Centre.position, -Centre.up, out hit, 2000, BodyLayerMask)) { if (!_setToSpawn) { _setToSpawn = true; // TODO:: implement a static metronome Metronome.addSpawner(id); } } //******** //PLEASE DONT DELETE THE BELLOW SEGMENT!!! //******** //IT IS USEFULL FOR DEBUGGING //******** //if (maxSpeed < carRigidBody.velocity.magnitude) //{ // Debug.Log("The speed is:"); // maxSpeed = carRigidBody.velocity.magnitude; // Debug.Log(maxSpeed); //} //RaycastHit hit; // TODO:: REMOVE:: *4: the *4 is just a temporary tweak. if (Math.Abs(powerInput) < 0.01f) { CarRigidBody.drag = 1; } else { CarRigidBody.drag = 4; } //if (Math.Abs(turnInput) > 0.1f) //{ // Debug.Log("TURNING"); //} if (Physics.Raycast(Centre.position, Vector3.down, out hit, HoverHeight, BodyLayerMask)) { CarRigidBody.AddRelativeForce(Vector3.forward * ((powerInput > 0) ? powerInput * Speed * 4 : powerInput * BackwardsSpeed * 4)); CarRigidBody.AddRelativeTorque(0f, turnInput * TurnSpeed, 0f); } Debug.Log("End of hovermoter"); }