Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - VahanDavtyan

Pages: [1]
1
General / Angular direction for circle collisions.
« on: March 12, 2023, 10:38:27 pm »
Hey, I've implemented a simple circle collision detection system.

bool SEMath::circle_collision(const TVector& a, const TVector& b,
                                                  const float& r1,  const float& r2)
{
        // (x2-x1)^2 + (y2-y1)^2 <= (r1+r2)^2
        float center_distance = square(b.x - a.x) + square(b.y - a.y);
        float collision_distance = square(r1 + r2);
        return center_distance <= collision_distance;
}

Upon collision, self circle will get it's opposite velocity (to bounce back) and the collided circle will get the get the velocity it was hit with:

CollidedActor->setVelocity(InActor->getVelocity());
InActor->setVelocity(InActor->getVelocity() * -1.f);

This works fine. But it's just a linear response. What I want is to consider at what angle the circles are colliding as well to be able to simulate a billiard like game by taking into account angular velocity as well but I have no idea how to approach this, any directions would be greatly appreciated. Thanks!


Pages: [1]
anything