fully fixed collision
Some checks failed
Build Project / build (ubuntu-latest) (push) Failing after 13m38s
Some checks failed
Build Project / build (ubuntu-latest) (push) Failing after 13m38s
This commit is contained in:
@@ -17,26 +17,40 @@ void checkCollision(){
|
|||||||
if(!en2->active){
|
if(!en2->active){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
printf("%d\n", en1->headgrounded);
|
//calculate overlap
|
||||||
|
|
||||||
float half = (en1->size + en2->size) * 0.5f;
|
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);
|
float overlapY = half - fabsf(en1->position.y - en2->position.y);
|
||||||
|
// check if any overlap
|
||||||
if (overlapX > 0 && overlapY > 0)
|
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)
|
||||||
en1->position.y = en2->position.y - half;
|
{
|
||||||
en1->velocity.y = 0;
|
// if the first entity is above the second put norml force on first entity
|
||||||
en1->velocity.x *= en2->drag;
|
en1->position.y = en2->position.y - half;
|
||||||
en1->headgrounded = true;
|
en1->velocity.y = 0;
|
||||||
} else {
|
en1->velocity.x *= en2->drag;
|
||||||
en1->headgrounded = false;
|
en1->headgrounded = true;
|
||||||
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);
|
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);
|
||||||
|
//direction resolution
|
||||||
if(en1->position.x < en2->position.x){
|
if(en1->position.x < en2->position.x){
|
||||||
|
//kill velocity so they cant go throughe achother
|
||||||
en1->velocity.x=0;
|
en1->velocity.x=0;
|
||||||
en2->velocity.x=0;
|
en2->velocity.x=0;
|
||||||
ApplyForce(
|
ApplyForce(
|
||||||
|
|||||||
BIN
wrldboxMacOS
BIN
wrldboxMacOS
Binary file not shown.
Reference in New Issue
Block a user