less messed up collision
Some checks failed
Build Project / build (push) Failing after 5m52s

This commit is contained in:
swim67667
2026-06-24 12:47:00 -04:00
parent c079ca620f
commit 9dee043d95
3 changed files with 17 additions and 16 deletions

View File

@@ -7,42 +7,41 @@
void checkCollision(){ void checkCollision(){
for(int u=0; u<=MAX_ENTITIES-1; u++){ for(int u=0; u<=MAX_ENTITIES-1; u++){
Entity *en1 = &entities[u]; Entity *en1 = &entities[u];
for(int j=1; j<=MAX_ENTITIES-1; j++){ if(!en1->active){
continue;
}
for(int j=u+1; j<=MAX_ENTITIES-1; j++){
if(u!=j){ if(u!=j){
Entity *en2 = &entities[j]; Entity *en2 = &entities[j];
if (fabsf(en1->position.x - en2->position.x) < (en1->size * 0.5f + en2->size * 0.5f)) if(!en2->active){
continue;
}
if (fabsf(en1->position.x - en2->position.x) < (en1->size * 0.5f + en2->size * 0.5f) && fabsf(en1->position.y - en2->position.y) < (en1->size * 0.5f + en2->size * 0.5f))
{ {
float forcex=fabs(((en1->mass+en2->mass)/2)*((((en1->velocity.x)+(scale*1.5))+((en2->velocity.x)+(scale*1.5)))/2)+((en1->force.x+en2->force.x)/2))*(scale);
float forcey=fabs(((en1->mass+en2->mass)/2)*((((en1->velocity.y)+(scale*1.5))+((en2->velocity.y)+(scale*1.5)))/2))*(scale);
if(en1->position.x < en2->position.x){ if(en1->position.x < en2->position.x){
ApplyForce( ApplyForce(
en1, en1,
(Vector2){-10000, 0} (Vector2){-forcex, -forcey}
); );
ApplyForce( ApplyForce(
en2, en2,
(Vector2){10000, 0} (Vector2){forcex, forcey}
); );
} }
else{ else{
ApplyForce( ApplyForce(
en1, en1,
(Vector2){10000, 0} (Vector2){forcex, -forcey}
); );
ApplyForce( ApplyForce(
en2, en2,
(Vector2){-10000, 0} (Vector2){-forcex, forcey}
); );
} }
} }
// if(fabsf(en1->position.y - en2->position.y) < (en1->size * 0.5f + en2->size * 0.5f)){
// ApplyForce(
// en1,
// (Vector2){0, 10000}
// );
// ApplyForce(
// en2,
// (Vector2){0, -10000}
// );
// }
} }
} }
} }

View File

@@ -12,6 +12,8 @@ extern bool isSimulating;
extern float simTime; extern float simTime;
extern const float scale;
extern const float MAX_PLAYER_SPEED; extern const float MAX_PLAYER_SPEED;
extern const float PLAYER_SPEED_FACTOR; extern const float PLAYER_SPEED_FACTOR;

Binary file not shown.