• Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

We're also offering banner ads on our site from just \$5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

### #Actuallukabratzi

Posted 04 February 2013 - 11:38 AM

if(aPhysicsComponent->m_mass > 0 && bPhysicsComponent->m_mass > 0)
{
Vector2D impulse = hitNormalA;
float restitutionCoefficient = -0.5f;

impulse *= (-(1.0f + restitutionCoefficient));
impulse /= (1/spriteAMass + 1/spriteBMass);

aPhysicsComponent->m_velocityChangesToApply += (hitNormalA);
bPhysicsComponent->m_velocityChangesToApply += (hitNormalB);
}

Would this work?

aPhysicsComponent->m_velocityChangesToApply += (hitNormalA) * impulse / spriteAMass;
bPhysicsComponent->m_velocityChangesToApply += (hitNormalB* impulse / spriteBMass;

Well both hitNormalA/B and impulse are both vectors.  Ideally impulse should be some force and direction applied on collision to both objects for a bounce effect, but I'm not even using that right now.  currently I'm just trying to move the objects apart by the penetration amount (hitNormalA = hitNormal * penetrationDepth) to separate them.

What's happening is that my method breaks when any one object is colliding with more than one other object.  I think that the middle object is being acted upon by both sides and can't resolve either collision as its always blocked by one of the other two objects.

So that makes me think that it may not necessarily be a problem with my collision resolution code but is instead more of a fundamental, conceptual problem with how I'm conducting my collision tests?

### #1lukabratzi

Posted 04 February 2013 - 11:38 AM

if(aPhysicsComponent->m_mass > 0 && bPhysicsComponent->m_mass > 0)
{
Vector2D impulse = hitNormalA;
float restitutionCoefficient = -0.5f;

impulse *= (-(1.0f + restitutionCoefficient));
impulse /= (1/spriteAMass + 1/spriteBMass);

aPhysicsComponent->m_velocityChangesToApply += (hitNormalA);
bPhysicsComponent->m_velocityChangesToApply += (hitNormalB);
}

Would this work?

aPhysicsComponent->m_velocityChangesToApply += (hitNormalA) * impulse / spriteAMass;
bPhysicsComponent->m_velocityChangesToApply += (hitNormalB* impulse / spriteBMass;

Well both hitNormalA/B and impulse are vectors.  Ideally impulse should be some force applied on collision for a bounce effect, but I'm not even using that right now.  currently I'm just trying to move the objects apart by the penetration amount (hitNormalA = hitNormal * penetrationDepth) to separate them.

What's happening is that my method breaks when any one object is colliding with more than one other object.  I think that the middle object is being acted upon by both sides and can't resolve either collision as its always blocked by one of the other two objects.

So that makes me think that it may not necessarily be a problem with my collision resolution code but is instead more of a fundamental, conceptual problem with how I'm conducting my collision tests?

PARTNERS