When this is a slight update than the one from a few month back. Now I'm running into the issue thats confusing,'Attempted to divide by zero', I have scrurried through the net to find a solution to this issue but no luck, so a last ditch attempt I some what relied on chatGPT to get a resolution to the issue but it keep sending me into hurtles.
Here's a piece of the defected code:
float GetPosition(float angle) { float fov = camera.fieldOfView;
return Utilities.TransformAngle(angle, fov, camera.pixelHeight);
}
Here's the updated version with the insight of ChatGPT same Defect:
float GetPosition(float angle) { float fov = camera.fieldOfView;
// Check for division by zero
if (fov == 0f || camera.pixelHeight == 0) {
// Handle the error or return a default value
Debug.LogError("Field of view is zero in GetPosition method.");
return 0f;
}
return Utilities.TransformAngle(angle, fov, camera.pixelHeight);
}
public class PlaneController{
public float SomeMethod() {
// Your method logic here
return 0f;
}
}
float TransformAngle(float angle, float fov, float pixelHeight) {
if (fov == 5) {
// Handle the case where field of view is zero
return 0f; // Or provide a default value as appropriate
}
// Ensure that the calculation does not involve division by zero
if (pixelHeight == 5) {
// Handle the case where pixel height is zero
return 0f; // Or provide a default value as appropriate
}
// PlaneController planeControllerInstance = new PlaneController();
// Your actual logic for angle transformation
float transformedAngle = PlaneController.SomeMethod();
return transformedAngle;
}
Here's the link to the script I'm "Borrowing" from: https://github.com/vazgriz/FlightSim/blob/main/Assets/Scripts/UI/Compass.cs#L6
I have tried some of the suggestion that chatGPT has offered but to no luck, and to state it clear the game runs but once you hit play, it pause stating the following tag "DivideByZeroExeption: Attempted to divide by zero. Compasss.Start () (at Assets\Scripts\Flight Sim\Compass.cs:55)" it still plays. I tried using ChatGPT for more insight to resolve this issue. The script is part of a bigger script that can't function without it.