something strange.

so,
I’m trying to figure out the best way for my character to break blocks.
(think 3rd person minecraft, or maybe terraria)
My first thought was to use an object(box) and it’s collider to “punch” the blocks.
So I have a cube with rendering turned off as a child of my player.
When i hit a key, I move the cube forward (transform.Find(“attackCollider”).Translate(1, 0, 0); ),
wait for a second (yield WaitForSeconds (1); ),
and then back. (transform.Find(“attackCollider”).Translate(-1, 0, 0); )

It works.
Probably not the best solution, but it does do something.
So as a total programming noob, I count this as a victory.
Anyway. When the cube moves back to its original position, the x and z values are super strange.
(-3.103535e-12, 0, 1.273723e-05) instead of the (0,0,0) that it was originally.

Anyone have any idea what is going on here?

also, if anyone has a suggestion as to what a better way to do this, I’d love to hear it.

Thanks,

They are floats they are exceptionally close to zero.

the e-12 means x 10 to the power -12

Thanks.
I thought it was something like that.
But I’m also wondering why it even happens.
If you add one, and then subtract one, shouldn’t it result in zero?
should I use a variable instead of an absolute value?
would and int be better than a float?

No, floating point numbers are only an approximation of what can fit in the 4 or 8 bytes allocated to them. Most times, the numbers don’t quite have an exact representation and this results in lots of tiny small errors which are unnoticeable most of the time.

I suggest you ignore them and pretend they’re zero, unless you’re building something that requires determinism which I don’t think you do.

And in the event you do need (0,0,0) just set them to (0,0,0) after the move is done.