Hey all,
I am creating an OverlapCollider
to find out, if something is colliding with it. I am also drawing it.
But even though, that in the scene the collider doesn’t seem to touch the object ( its about 3 cm above it), a collision seems to be happening. The collision with cube 1.7 is correct, the collision with cube 2 should not happen from my point of view. I have checked the collider of the cube 2, and it’s fine.
Both, the Collider
and the drawWireCube
are placed at the same center with the same dimensions, so I don’t understand how this could happen.
Any ideas, what is going wrong here? Either the drawCube
is not drawn where the Collider
really is or I don’t know… I’m afraid it’s something stupid, but I just can’t figure it out…
My code:
…
data.ledgePoint = new Vector3(hit.point.x, hit.point.y + 0.03f, hit.point.z) ;
if (data.isCrouching)
{
data.dimensions = new Vector3(0.84f, 1.6f, 0.84f);
data.center = new Vector3(data.ledgePoint.x + (data.dimensions.x / 2), data.ledgePoint.y + 0.8f, data.ledgePoint.z);
}
else
{
data.dimensions = new Vector3(0.6f, 2.1f, 0.6f);
data.center = new Vector3(data.ledgePoint.x + (data.dimensions.x / 2), data.ledgePoint.y + 1.05f, data.ledgePoint.z);
}
Collider[] spaceCollider = Physics.OverlapBox(data.center, data.dimensions, Quaternion.identity, ~data.playerLayer);
int i = 0;
while (spaceCollider.Length != 0 && i < spaceCollider.Length)
{
Debug.Log("Hit: " + spaceCollider[i].name);
i++;
}
…
void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawWireCube(data.center, data.dimensions);
}
Thank you Huxi.