Cubes Inaccurate Collision Detection

I am having an issue using the cubes framework. It seems that the collision point that is detected is somewhat distant from the actual location, resulting in the correct cube not being found correctly.
Trying to get a cube at x=8, y=6, z=8 sometimes results in this:
[Vector3Int x=8 y=6 z=7]// location of “block”
(8.058348, 6.0886364, 7.98) //collision point.

Why is this? I have a RigidBodyControl in place for when I develop better collision detection, however, I removed that, and the problem persists. Also, there don’t appear to be any locations on the cube that are affected the most. It seems fairly random. Sometimes the collision is detected, other times, it isn’t.

1 Like

Type int is simply rounded down.

For understanding:

int result = (int)Math.round(3.8);   
System.out.println(result); 

4

int result = (int)Math.round(3.3);
System.out.println(result);            

3

In your case:

int result = (int)Math.floor(3.8);   
System.out.println(result);         

3

int result = (int)Math.floor(3.3);
System.out.println(result);   

3

1 Like

And it probably depends on the side of the block you hit.

0,0,0 of the block versus 1, 1, 1 of the block, etc.

1 Like

I see what is being said here, but I am not understanding why the accuracy is so low. I understand that the integer is round down.
If the surface is flat at lets say x=8. Then why would the collision point be located at 7.98? I just feel that this is a little far off.

1 Like

Perhaps this is a calculation error, the fact is that the ray has inherent problems.

The intersection of the point is not defined for the vector. Vector3f(0, -1, 0)
The point is defined: Vector3f(0.00001f, -1, 0)

I think you can check out a primitive plane. cubes framework a problem, maybe…

1 Like

Thanks for the help. As it turned out, I was colliding around an outline that was surrounding the block. Keep that in mind folks. Make sure the mesh you are colliding with is actually the one you intend it to be.

1 Like