- Home /
The question is answered, right answer was accepted
Check my math...?
Yes i know this script is a mess but it's my first time trying mesh generation via code. The code returns no error so it has to be a math error
Here is the line that contains the math i wasn't sure how to contain the order of operations so this is how i typed it and it returns (0, 0, 0) when it is suppose to be (-5, -0, 5)
float maxRoomSize = 100;
vertices [1] = new Vector3 (-1 * 1 / 2 * Mathf.Sqrt (maxRoomSize), 0, 1 / 2 * Mathf.Sqrt (maxRoomSize));
//Square root of 100 is 10
//10 * 1/2 = 5
//5 * -1 = -5 why is it 0?
I'm almost positive its an order of operations error but i'll let someone else judge that
There is no problem with the math, Post more of the code. also, as a quick debug, try to set the vector to (-5,0,5) manually,not using calculations and see if it still comes out as 000
Answer by flaviusxvii · Sep 21, 2016 at 02:31 AM
You're suffering from integer division.. try changing 2 to 2f and it'll work.
That would be it never learned about "integer division" but after reading about it that does make a lot more sense probably why people just use floats as defaults so this doesn't happen :)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Player rapidly accelerating instead of stopping 1 Answer
Projectile motion arc 2d 1 Answer