I’ve always converted float to int to get an easy way of getting a quick, but not that precise way of returning a position comparison:
if (transform.position == new Vector3((int)pos.x, (int)pos.y, (int)pos.z))
I’ve used ‘ranges’ and found using things like Mathf.Approximately never really did the job without it feeling heavy. What drawbacks are there to using the int conversion on things like this, I’m so impressed by how simply and well it works though.
I believe it’s just treated as just another position, so it’s only less precise. The Vector3 equality operator actually uses Mathf.Approximately already, so doing something like this is completely fine:
It works great, but I’ve found in my current circumstances directly comparing two positions like that when using a controller (especially xbox controller ) will never complete due to float precision.
If you mean litterally (as in typing all those “(int)” in every comparison you make) then I would say it’s a violation of the DRY (dont-repeat-yourself) priciple. It also might haunt you with bugs if you forget it on one parameter every now and then. Better put it into an extension method or something similar.
There is a Vector3Int type in Unity which might be handy in your case. It depends on whether or not your really need that float precision. One approach would be to do all your stuff in Vector3Int and just multiply your values with 1000 for SET operations and divide by 1000 for Get operations. 1000 is just an example, use whatever precision you need.