fully fixed collision
Some checks failed
Build Project / build (ubuntu-latest) (push) Failing after 13m38s

This commit is contained in:
swim67667
2026-06-28 14:40:40 -04:00
parent fded40cbd9
commit 277bedf122
2 changed files with 29 additions and 15 deletions

View File

@@ -17,26 +17,40 @@ void checkCollision(){
if(!en2->active){
continue;
}
printf("%d\n", en1->headgrounded);
//calculate overlap
float half = (en1->size + en2->size) * 0.5f;
float overlapX = half - fabsf(en1->position.x - en2->position.x);
float overlapXcheck = half - fabsf(en1->position.x - en2->position.x);
float overlapXapply = ((en1->size + en2->size) * 0.43f) - fabsf(en1->position.x - en2->position.x);
float overlapY = half - fabsf(en1->position.y - en2->position.y);
if (overlapX > 0 && overlapY > 0)
// check if any overlap
if (overlapXcheck > 0 && overlapY > 0)
{
if (overlapY < overlapX && en1->position.y < en2->position.y)
if (overlapY < overlapXapply)
{
// top collision
if (en1->position.y < en2->position.y)
{
// if the first entity is above the second put norml force on first entity
en1->position.y = en2->position.y - half;
en1->velocity.y = 0;
en1->velocity.x *= en2->drag;
en1->headgrounded = true;
} else {
en1->headgrounded = false;
}
else
{
// if the second entity is above the fisrt put norml force on second entity
en2->position.y = en1->position.y - half;
en2->velocity.y = 0;
en2->velocity.x *= en1->drag;
en2->headgrounded = true;
}
}
else
{
// push apart calculation
float forcex = fabsf(((en1->mass+en2->mass)/2)*((((en1->velocity.x)+(scale))+((en2->velocity.x)+(scale)))/2))*(scale*1.5);
float forcey=fabsf(((en1->mass+en2->mass)/2)*((((en1->velocity.y)+(scale))+((en2->velocity.y)+(scale)))/2))*(scale/4);
//direction resolution
if(en1->position.x < en2->position.x){
//kill velocity so they cant go throughe achother
en1->velocity.x=0;
en2->velocity.x=0;
ApplyForce(

Binary file not shown.