Update Velocity on 3D collision with Wall/OBB

  c++, collision, collision-detection, glm-math, physics

I’m trying to handle Sphere->OBB Resolution in 3D space and it all seems works however I seem to have an issue where the velocity after collision is higher than before, the sphere will never come to a complete stop and continue bouncing everywhere. I’ve tried implementing elastic collision where my first object is the moving ball and my 2nd object is the wall like so.

vf1 = (m1 - m2) * vi1 / m1 + m2

Is what I’m using to calculate the new velocity like so in my collision resolution below.

glm::vec3 Physics::SphereOBB_Resolution(Sphere* sphere, Cube* cube)
{
    // Calculate Normal
    glm::vec3 closest_point = ClosestPoint(cube, sphere->position);
    glm::vec3 normal = glm::normalize(sphere->position - closest_point);

    // Reposition Ball
    if (glm::distance(sphere->position, closest_point) < sphere->size.x*sphere->size.x)
    {
        sphere->position = closest_point + (sphere->size.x*sphere->size.x)*4.0f;
    }

    // Calculate Reflection
    sphere->movement->velocity = glm::reflect(sphere->movement->velocity, normal);

    // Update Velocity -> Causes Ball to stop completely on collision
    sphere->movement->velocity = (sphere->size - cube->size) * sphere->movement->velocity / sphere->size + cube->size;

    return sphere->movement->velocity;
}

where size, position and velocity are all vec3, and the cube is a stationary object.

Source: Windows Questions C++

LEAVE A COMMENT