implement tuning values for elasticity

implement tuning values for elasticity

add grounded check to movebox and give jump back when bouncing

fix styling issues

fix jumps being given back at ceilings
This commit is contained in:
Marvin Winkens 2022-06-12 14:06:58 +02:00 committed by mwinkens
parent 5a7fa108a6
commit e1ba77d3dc
6 changed files with 36 additions and 9 deletions

View file

@ -122,7 +122,7 @@ void CCharacter::HandleNinja()
// Set velocity
m_Core.m_Vel = m_Core.m_Ninja.m_ActivationDir * g_pData->m_Weapons.m_Ninja.m_Velocity;
vec2 OldPos = m_Pos;
Collision()->MoveBox(&m_Core.m_Pos, &m_Core.m_Vel, vec2(m_ProximityRadius, m_ProximityRadius), 0.f);
Collision()->MoveBox(&m_Core.m_Pos, &m_Core.m_Vel, vec2(m_ProximityRadius, m_ProximityRadius), vec2(GetTuning(m_TuneZone)->m_GroundElasticityX, GetTuning(m_TuneZone)->m_GroundElasticityY));
// reset velocity so the client doesn't predict stuff
m_Core.m_Vel = vec2(0.f, 0.f);

View file

@ -475,7 +475,7 @@ bool CCollision::TestBox(vec2 Pos, vec2 Size) const
return false;
}
void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elasticity) const
void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, vec2 Elasticity, bool *pGrounded) const
{
// do the move
vec2 Pos = *pInoutPos;
@ -487,6 +487,9 @@ void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elas
if(Distance > 0.00001f)
{
float Fraction = 1.0f / (float)(Max + 1);
float ElasticityX = clamp(Elasticity.x, -1.0f, 1.0f);
float ElasticityY = clamp(Elasticity.y, -1.0f, 1.0f);
for(int i = 0; i <= Max; i++)
{
// Early break as optimization to stop checking for collisions for
@ -512,15 +515,17 @@ void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elas
if(TestBox(vec2(Pos.x, NewPos.y), Size))
{
if(pGrounded && ElasticityY > 0 && Vel.y > 0)
*pGrounded = true;
NewPos.y = Pos.y;
Vel.y *= -Elasticity;
Vel.y *= -ElasticityY;
Hits++;
}
if(TestBox(vec2(NewPos.x, Pos.y), Size))
{
NewPos.x = Pos.x;
Vel.x *= -Elasticity;
Vel.x *= -ElasticityX;
Hits++;
}
@ -528,10 +533,12 @@ void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elas
// this is a real _corner case_!
if(Hits == 0)
{
if(pGrounded && ElasticityY > 0 && Vel.y > 0)
*pGrounded = true;
NewPos.y = Pos.y;
Vel.y *= -Elasticity;
Vel.y *= -ElasticityY;
NewPos.x = Pos.x;
Vel.x *= -Elasticity;
Vel.x *= -ElasticityX;
}
}

View file

@ -42,7 +42,7 @@ public:
int IntersectLineTeleWeapon(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr) const;
int IntersectLineTeleHook(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr) const;
void MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, int *pBounces) const;
void MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elasticity) const;
void MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, vec2 Elasticity, bool *pGrounded = nullptr) const;
bool TestBox(vec2 Pos, vec2 Size) const;
// DDRace

View file

@ -465,7 +465,17 @@ void CCharacterCore::Move()
vec2 NewPos = m_Pos;
vec2 OldVel = m_Vel;
m_pCollision->MoveBox(&NewPos, &m_Vel, PhysicalSizeVec2(), 0);
bool Grounded = false;
m_pCollision->MoveBox(&NewPos, &m_Vel, PhysicalSizeVec2(),
vec2(m_Tuning.m_GroundElasticityX,
m_Tuning.m_GroundElasticityY),
&Grounded);
if(Grounded)
{
m_Jumped &= ~2;
m_JumpedTotal = 0;
}
m_Colliding = 0;
if(m_Vel.x < 0.001f && m_Vel.x > -0.001f)

View file

@ -224,7 +224,14 @@ void CCharacter::HandleNinja()
// Set velocity
m_Core.m_Vel = m_Core.m_Ninja.m_ActivationDir * g_pData->m_Weapons.m_Ninja.m_Velocity;
vec2 OldPos = m_Pos;
Collision()->MoveBox(&m_Core.m_Pos, &m_Core.m_Vel, vec2(GetProximityRadius(), GetProximityRadius()), 0.f);
vec2 GroundElasticity;
if(!m_TuneZone)
GroundElasticity = vec2(GameServer()->Tuning()->m_GroundElasticityX, GameServer()->Tuning()->m_GroundElasticityY);
else
GroundElasticity = vec2(GameServer()->TuningList()[m_TuneZone].m_GroundElasticityX, GameServer()->TuningList()[m_TuneZone].m_GroundElasticityY);
Collision()->MoveBox(&m_Core.m_Pos, &m_Core.m_Vel, vec2(GetProximityRadius(), GetProximityRadius()), GroundElasticity);
// reset velocity so the client doesn't predict stuff
m_Core.m_Vel = vec2(0.f, 0.f);

View file

@ -59,3 +59,6 @@ MACRO_TUNING_PARAM(GrenadeFireDelay, grenade_fire_delay, 500, "Delay of firing g
MACRO_TUNING_PARAM(LaserFireDelay, laser_fire_delay, 800, "Delay of firing laser laser")
MACRO_TUNING_PARAM(NinjaFireDelay, ninja_fire_delay, 800, "Delay of firing ninja")
MACRO_TUNING_PARAM(HammerHitFireDelay, hammer_hit_fire_delay, 320, "Delay of hammering (when hitting another tee)")
MACRO_TUNING_PARAM(GroundElasticityX, ground_elasticity_x, 0, "Wall elasticity")
MACRO_TUNING_PARAM(GroundElasticityY, ground_elasticity_y, 0, "Ground/ceiling elasticity")