I'm creating a small game in Unity with C#, I'm not allowed to use any of the built in physics or colliders. What I have is a platform with a weight object on it. With the arrow keys you can tilt the platforms angle. The weight on top should then react accordingly to the given tilt angle. I have calculated everything with the friction, max friction, normal force a.s.o. The thing that doesn't work is when you press a key to change the tilt, the force on the object should change accordingly, and if the force on the weight is greater that the maximum friction force, then the weight should move. Here is a simplified example of my code.
public float m = 35;
public float µ = 0.15f;
public float g = 9.82f; //(N/kg)
public float N;
public double deg = 0;
Fmax = m * g * µ;
if (Input.GetKeyDown(KeyCode.UpArrow)) {
deg++;
N = m * g * µ * (Math.Cos(deg) * (180.0 / Math.PI));
platform.transform.Rotate(0, 0, deg, Space.Self);
} else if (Input.GetKeyDown(KeyCode.DownArrow)) {
deg--;
N = m * g * µ * (Math.Cos(deg) * (180.0 / Math.PI));
platform.transform.Rotate(0, 0, deg, Space.Self);
}
if(N > Fmax) {
// Do the rest of the code
}
I think that the problem has to do with that Math.Cos(deg)
turns the deg into a radian, but I tried to then covert back the reg to a deg with: (180.0 / Math.PI)
. I can get everything to work on my calculator but not in the code.