diff --git a/libraries/shared/src/ShapeCollider.cpp b/libraries/shared/src/ShapeCollider.cpp index f5836f373b..7c29fbae00 100644 --- a/libraries/shared/src/ShapeCollider.cpp +++ b/libraries/shared/src/ShapeCollider.cpp @@ -664,13 +664,14 @@ bool sphereAACube(const glm::vec3& sphereCenter, float sphereRadius, const glm:: glm::vec3 direction; BA /= maxBA; glm::modf(BA, direction); - direction = glm::normalize(direction); + float lengthDirection = glm::length(direction); + direction /= lengthDirection; // compute collision details collision->_type = COLLISION_TYPE_AACUBE; collision->_floatData = cubeSide; collision->_vecData = cubeCenter; - collision->_penetration = (halfCubeSide + sphereRadius - distance * glm::dot(BA, direction)) * direction; + collision->_penetration = (halfCubeSide * lengthDirection + sphereRadius - maxBA * glm::dot(BA, direction)) * direction; collision->_contactPoint = sphereCenter + sphereRadius * direction; } collision->_type = COLLISION_TYPE_AACUBE;