Hi everyone, I’m trying to calculate the angle on a “side-face” of a cube. And what I’ve done is that I’ve placed three empty GameObjects that are always placed on:
The middle of a face of the cube, the edge of the cube next to the first one and lastly an angle anchor which has the same position as the first one except +2 on the z axis.
What I want to achieve is two things:
Be able to calculate the angle of the face where these empty GameObjects are using Vector.Distance and Law of Cosines.
And the more difficult one is to be able to set the angle of said face in any given angle…
I know what to do with the first one if this was made using a regular calculator, but I’m not sure how to achieve the same effect in Mono C#. Especially Mathf.Cos because it has to be cos^-1…
Here’s what I’ve managed to cook up right now, and without moving any of the edges the value should be 90 degrees but for some reason it returns 50 point something.
Thanks for the replies, I’m looking into it now trying to figure it out.
Basically I’ve programmed my own cube and I’m using handles on each edge of the cube to adjust the shape. And what I’m trying to do now is being able to set a specific angle to one of these faces by adjusting the edges accordingly. But for starters I’m trying to find out what the current angle is by manually adjusting the handles in the editor.
Angle isn’t enough information to do anything with.
If I told you I rolled a die, and the 6 face was at 90 degrees. What does that even mean? 90 degrees what? 90 degrees about the axis orthogonal to the 6-face? 90 degrees off what origin orientation, what is 0 degrees look like?
An angle describes the relationship between 2 orientations.
…
Anyways, my entire point is that the first key to programming and math is being able to describe the specifics of what you’re trying to calculate. And many people on these forums are always asking “how do I calculate the angle of this”? The angle of what? Off what?
To this cube there’s a child object for each edge, there’s also child objects for each face that is offset from the cube on the x/y/z by one depending on which side it is.
And what I’m doing is calculating the angle of the face (of the cube between the edges) by measuring the distance between all three and using the following formula to find out the angle:
And later on I’m subdiving this value and fiddling with it to make it so that when the face is flat it’s supposed to read 0 degrees, and if you adjust the edges in any way the value will adjust. For example adjusting the left side will yield +something to the angle, and the right side will yield -something to the angle.