Entities experience water resistance
This commit is contained in:
parent
5b63a7fe98
commit
52d86728e6
@ -927,12 +927,13 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
|
|||||||
float fallspeed;
|
float fallspeed;
|
||||||
if (IsBlockWater(BlockIn))
|
if (IsBlockWater(BlockIn))
|
||||||
{
|
{
|
||||||
fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water.
|
fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water
|
||||||
|
ApplyFriction(NextSpeed, 0.7, a_Dt);
|
||||||
}
|
}
|
||||||
else if (BlockIn == E_BLOCK_COBWEB)
|
else if (BlockIn == E_BLOCK_COBWEB)
|
||||||
{
|
{
|
||||||
NextSpeed.y *= 0.05; // Reduce overall falling speed
|
NextSpeed.y *= 0.05; // Reduce overall falling speed
|
||||||
fallspeed = 0; // No falling.
|
fallspeed = 0; // No falling
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -943,20 +944,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Friction on ground
|
ApplyFriction(NextSpeed, 0.7, a_Dt);
|
||||||
if (NextSpeed.SqrLength() > 0.0004f)
|
|
||||||
{
|
|
||||||
NextSpeed.x *= 0.7f / (1 + a_Dt);
|
|
||||||
if (fabs(NextSpeed.x) < 0.05)
|
|
||||||
{
|
|
||||||
NextSpeed.x = 0;
|
|
||||||
}
|
|
||||||
NextSpeed.z *= 0.7f / (1 + a_Dt);
|
|
||||||
if (fabs(NextSpeed.z) < 0.05)
|
|
||||||
{
|
|
||||||
NextSpeed.z = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we
|
// Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we
|
||||||
@ -1062,6 +1050,27 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cEntity::ApplyFriction(Vector3d & a_Speed, double a_SlowdownMultiplier, float a_Dt)
|
||||||
|
{
|
||||||
|
if (a_Speed.SqrLength() > 0.0004f)
|
||||||
|
{
|
||||||
|
a_Speed.x *= a_SlowdownMultiplier / (1 + a_Dt);
|
||||||
|
if (fabs(a_Speed.x) < 0.05)
|
||||||
|
{
|
||||||
|
a_Speed.x = 0;
|
||||||
|
}
|
||||||
|
a_Speed.z *= a_SlowdownMultiplier / (1 + a_Dt);
|
||||||
|
if (fabs(a_Speed.z) < 0.05)
|
||||||
|
{
|
||||||
|
a_Speed.z = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cEntity::TickBurning(cChunk & a_Chunk)
|
void cEntity::TickBurning(cChunk & a_Chunk)
|
||||||
{
|
{
|
||||||
// Remember the current burning state:
|
// Remember the current burning state:
|
||||||
|
@ -535,6 +535,12 @@ protected:
|
|||||||
|
|
||||||
virtual void Destroyed(void) {} // Called after the entity has been destroyed
|
virtual void Destroyed(void) {} // Called after the entity has been destroyed
|
||||||
|
|
||||||
|
/** Applies friction to an entity
|
||||||
|
@param a_Speed The speed vector to apply changes to
|
||||||
|
@param a_SlowdownMultiplier The factor to reduce the speed by
|
||||||
|
*/
|
||||||
|
static void ApplyFriction(Vector3d & a_Speed, double a_SlowdownMultiplier, float a_Dt);
|
||||||
|
|
||||||
/** Called in each tick to handle air-related processing i.e. drowning */
|
/** Called in each tick to handle air-related processing i.e. drowning */
|
||||||
virtual void HandleAir(void);
|
virtual void HandleAir(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user