The way to cope with collisions which have small relative speeds, however exterior forces resembling gravity?
Think about a stage with a 2D field, rotated 30 levels and positioned on the ground.
Gravity acts within the field, strikes it in direction of the bottom and causes a collision. The collision is resolved utilizing a impulse -based collision decision mannequinHowever as a result of the relative velocity of the field on the collision level is near 0, the impulse could be very small.
This appears to make the field really feel on its edge throughout an extended unnatural interval, till enough angular velocity is lastly gathered to fall to its aspect.
It appears that evidently my collision decision mannequin lacks a element that may clarify the impact of exterior forces resembling gravity on a collision that takes place with low relative velocity. Is there an accurate solution to give an account of this?
Share a code beneath in case there’s an error:
float Simulator::calculateCollisionImpulse(const CollisionDetails &collision, const glm::vec2 ®ular,
const glm::vec2 &relative_velocity,
const glm::vec2 &relative_a, const glm::vec2 &relative_b,
float total_mass) {
BodyId id_a = collision.bodyA();
BodyId id_b = collision.bodyB();
RigidBody& body_a = m_bodies(id_a);
RigidBody& body_b = m_bodies(id_b);
float impulse_force = glm::dot(relative_velocity, regular);
float inertia_magnitude_a = body_a.invert_moment * Vec2Utilities::cross2(relative_a, regular);
float inertia_magnitude_b = body_b.invert_moment * Vec2Utilities::cross2(relative_b, regular);
// Compute cross product: inertia x relative_position
glm::vec2 inertia_a = {-inertia_magnitude_a * relative_a.y,inertia_magnitude_a * relative_a.x};
glm::vec2 inertia_b = {-inertia_magnitude_b * relative_b.y,inertia_magnitude_b * relative_b.x};
// Whole angular momentum within the course of collision
float angular_effect = glm::dot(inertia_a + inertia_b, regular);
// Calculate whole impulse
const float restitution = body_a.restitution * body_b.restitution;
return (-(1.0f + restitution) * impulse_force) / (total_mass + angular_effect);
}
void Simulator::applyCollisionImpulse(const CollisionDetails &collision, const glm::vec2 ®ular,
const glm::vec2 &relative_a, const glm::vec2 &relative_b,
float impulse) {
BodyId id_a = collision.bodyA();
BodyId id_b = collision.bodyB();
glm::vec2 full_impulse = regular * impulse;
addImpulse(id_a, full_impulse);
addImpulse(id_b, -full_impulse);
addAngularImpulse(id_a, Vec2Utilities::cross2(relative_a, full_impulse));
addAngularImpulse(id_b, Vec2Utilities::cross2(relative_b, -full_impulse));
}