mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-02-21 03:11:24 +00:00
Change player collision again, they bounce away from each other naturally
Need to meddle and test with a "minimum bounce" still
This commit is contained in:
parent
e5a32eb699
commit
8315ccd475
3 changed files with 27 additions and 36 deletions
48
src/k_kart.c
48
src/k_kart.c
|
@ -1039,12 +1039,12 @@ static void K_KartItemRouletteByDistance(player_t *player, ticcmd_t *cmd)
|
|||
|
||||
//{ SRB2kart p_user.c Stuff
|
||||
|
||||
void K_KartBilliards(mobj_t *mobj1, mobj_t *mobj2, boolean bounce)
|
||||
void K_KartBouncing(mobj_t *mobj1, mobj_t *mobj2, boolean bounce)
|
||||
{
|
||||
mobj_t *fx;
|
||||
fixed_t ndistx, ndisty, ndistlength;
|
||||
fixed_t a1, a2;
|
||||
fixed_t optimizedP;
|
||||
fixed_t momdifx, momdify;
|
||||
fixed_t distx, disty;
|
||||
fixed_t dot, p;
|
||||
fixed_t mass1, mass2;
|
||||
|
||||
if (!mobj1 || !mobj2)
|
||||
|
@ -1064,38 +1064,22 @@ void K_KartBilliards(mobj_t *mobj1, mobj_t *mobj2, boolean bounce)
|
|||
|
||||
mass1 = mass2 = 1*FRACUNIT;
|
||||
if (mobj1->player)
|
||||
mass1 = (1+mobj1->player->kartweight*20)*FRACUNIT;
|
||||
mass1 = (mobj1->player->kartweight)*FRACUNIT;
|
||||
if (mobj2->player)
|
||||
mass2 = (1+mobj2->player->kartweight*20)*FRACUNIT;
|
||||
mass2 = (mobj2->player->kartweight)*FRACUNIT;
|
||||
|
||||
// find normalised vector from centre of each mobj
|
||||
ndistx = mobj1->x - mobj2->x;
|
||||
ndisty = mobj1->y - mobj2->y;
|
||||
ndistlength = P_AproxDistance(ndistx, ndisty);
|
||||
ndistx = FixedDiv(ndistx, ndistlength);
|
||||
ndisty = FixedDiv(ndisty, ndistlength);
|
||||
momdifx = mobj1->momx - mobj2->momx;
|
||||
momdify = mobj1->momy - mobj2->momy;
|
||||
distx = mobj1->x - mobj2->x;
|
||||
disty = mobj1->y - mobj2->y;
|
||||
dot = FixedMul(momdifx, distx) + FixedMul(momdify, disty);
|
||||
p = FixedDiv(dot, FixedMul(distx, distx)+FixedMul(disty, disty));
|
||||
|
||||
// find length of the component from the movement along n
|
||||
a1 = FixedMul(mobj1->momx, ndistx) + FixedMul(mobj1->momy, ndisty);
|
||||
a2 = FixedMul(mobj2->momx, ndistx) + FixedMul(mobj2->momy, ndisty);
|
||||
mobj1->momx = mobj1->momx - FixedMul(FixedMul(FixedDiv(2*mass2, mass1 + mass2), p), distx);
|
||||
mobj1->momy = mobj1->momy - FixedMul(FixedMul(FixedDiv(2*mass2, mass1 + mass2), p), disty);
|
||||
|
||||
optimizedP = FixedDiv(FixedMul(2*FRACUNIT, a1 - a2), mass1 + mass2);
|
||||
|
||||
// calculate new movement of mobj1
|
||||
mobj1->momx = mobj1->momx - FixedMul(FixedMul(optimizedP, mass2), ndistx);
|
||||
mobj1->momy = mobj1->momy - FixedMul(FixedMul(optimizedP, mass2), ndisty);
|
||||
|
||||
// calculate new movement of mobj2
|
||||
mobj2->momx = mobj2->momx + FixedMul(FixedMul(optimizedP, mass1), ndistx);
|
||||
mobj2->momy = mobj2->momy + FixedMul(FixedMul(optimizedP, mass1), ndisty);
|
||||
|
||||
// In addition to knocking players based on their momentum into each other
|
||||
// I will bounce them away from each other based on weight
|
||||
optimizedP = FixedDiv(cv_collideminimum.value*FRACUNIT, mass1 + mass2); // reuse these variables for helping decide bounce speed
|
||||
a1 = FixedMul(optimizedP, mass2);
|
||||
a2 = FixedMul(optimizedP, mass1);
|
||||
P_Thrust(mobj1, R_PointToAngle2(mobj1->x, mobj1->y, mobj2->x, mobj2->y)+ANGLE_180, a1);
|
||||
P_Thrust(mobj2, R_PointToAngle2(mobj1->x, mobj1->y, mobj2->x, mobj2->y), a2);
|
||||
mobj2->momx = mobj2->momx - FixedMul(FixedMul(FixedDiv(2*mass1, mass1 + mass2), p), -distx);
|
||||
mobj2->momy = mobj2->momy - FixedMul(FixedMul(FixedDiv(2*mass1, mass1 + mass2), p), -disty);
|
||||
|
||||
if (bounce == true) // Perform a Goomba Bounce.
|
||||
mobj1->momz = -mobj1->momz;
|
||||
|
|
|
@ -15,7 +15,7 @@ UINT8 K_GetKartColorByName(const char *name);
|
|||
|
||||
void K_RegisterKartStuff(void);
|
||||
|
||||
void K_KartBilliards(mobj_t *mobj1, mobj_t *mobj2, boolean bounce);
|
||||
void K_KartBouncing(mobj_t *mobj1, mobj_t *mobj2, boolean bounce);
|
||||
void K_KartPlayerThink(player_t *player, ticcmd_t *cmd);
|
||||
void K_SpinPlayer(player_t *player, mobj_t *source);
|
||||
void K_SquishPlayer(player_t *player, mobj_t *source);
|
||||
|
|
13
src/p_map.c
13
src/p_map.c
|
@ -1597,6 +1597,12 @@ static boolean PIT_CheckThing(mobj_t *thing)
|
|||
}
|
||||
else if (thing->player) // bounce when players collide
|
||||
{
|
||||
// see if it went over / under
|
||||
if (tmthing->z > thing->z + thing->height)
|
||||
return true; // overhead
|
||||
if (tmthing->z + tmthing->height < thing->z)
|
||||
return true; // underneath
|
||||
|
||||
if (thing->player->kartstuff[k_growshrinktimer] || thing->player->kartstuff[k_squishedtimer]
|
||||
|| thing->player->kartstuff[k_bootaketimer] || thing->player->kartstuff[k_spinouttimer]
|
||||
|| thing->player->kartstuff[k_startimer] || thing->player->kartstuff[k_justbumped]
|
||||
|
@ -1608,14 +1614,15 @@ static boolean PIT_CheckThing(mobj_t *thing)
|
|||
}
|
||||
|
||||
if (P_IsObjectOnGround(thing) && tmthing->momz < 0)
|
||||
K_KartBilliards(tmthing, thing, true);
|
||||
K_KartBouncing(tmthing, thing, true);
|
||||
else if (P_IsObjectOnGround(tmthing) && thing->momz < 0)
|
||||
K_KartBilliards(thing, tmthing, true);
|
||||
K_KartBouncing(thing, tmthing, true);
|
||||
else
|
||||
K_KartBilliards(tmthing, thing, false);
|
||||
K_KartBouncing(tmthing, thing, false);
|
||||
|
||||
thing->player->kartstuff[k_justbumped] = 6;
|
||||
tmthing->player->kartstuff[k_justbumped] = 6;
|
||||
return true;
|
||||
}
|
||||
// Are you touching the side of the object you're interacting with?
|
||||
else if (thing->z - FixedMul(FRACUNIT, thing->scale) <= tmthing->z + tmthing->height
|
||||
|
|
Loading…
Reference in a new issue