41 Replies
you mean in the debug log?
GitHub
UnityCsReference/Runtime/Export/Math/Vector2.cs at b44c4cc9e4ce3dfa...
Unity C# reference source code. Contribute to Unity-Technologies/UnityCsReference development by creating an account on GitHub.
that's most likely why it does
even tho it's truncated, they remain floats, and the
ToString()
method formats them with the F2
format option, and by default I think Debug.Log transforms everything using the ToString()
method before printing it, which is what Console.WriteLine
in normal C# does, and what makes most senseYou can use
Vector2Int
if you want it to have integer parts
I think it fits your use case moreYeah, if you don't need floating point arithmetic use
Vector2Int
Also,
Math
is the default c# math class that works on doubles. Mathf
is provided by unity and works on floats. Since floats are smaller it runs faster, so i recommend you switch to using Mathf
instead.it doesn't really do anything else, it doesn't run faster, it's just a wrapper so you don't need to be casting values every time
Really?
basically, it internally uses the C# Math API
ok then
GitHub
UnityCsReference/Runtime/Export/Math/Mathf.cs at master · Unity-Tec...
Unity C# reference source code. Contribute to Unity-Technologies/UnityCsReference development by creating an account on GitHub.
Here is the source if you want to check that out
well, it contains some more methods, but for the methods that are common between these 2 APIs, it uses the C# Math API
I love the fact that they are making pull requests to a reference repository, and they make a lot of work for it to never be checked out 😹
News to me. I thought it was different, especially since Microsoft added their own
MathF
class,it's different
I have just now realized that the reson I couldnt find truncate under the MathF class is because I was using the popup option Mathf
well, basically it's what's missing from the Math api that The unity MathF has but the C# Math doesn't
Oh ya,
Mathf
and MathF
are different classes
real funjust incase c# was too straightforward
Remember, if you can do something, you must be able to do it in 5 almost indistinguishable ways
I have changed them out to ints, but I get the same problem
you have to change the base type to Vector2Int
did that
are 2 and 2.00 interchangeable?
the
2.00
is just string formatting
the internal value is simply 00000010
ah ok
should be. If you want to log it differently you can do
$"({vector2int.x}, {vector2int.y})"
this will avoid tostring on the vector and call tostring on the ints directlySharpLab
C#/VB/F# compiler playground.
@41phaNum3r1ca1 Actually another thing. Truncate will cause a bug if x or y is negative. You should be using Floor instead
Truncate(-1.3) = -1
Floor(-1.3) = -2
the former is what I want 👍
Isn't truncating values just casting them to ints?
Are you sure? With truncate the the tiles left and right(and up or down) of the axes will be given the sime tile position
wouldnt floor have the same problem?
no
if -1.3 floored is 2, it will be in the same position as 2
that is correct
let me draw a diagram
itl help understand
ok
ah, I was confused because you had made a typo
I understand what you mean now
oh i missed the negatives
thats my fault sorry
I probably will not change it, as the way I have it creating will always be in one quadrant. Regardless, thank you for your help
If its all positive then you should be fine