Physics enhancements
Minecarts no longer glitch on flat rails Improved acceleration, speed limit, and stopping
This commit is contained in:
parent
9f59b9a093
commit
acaae7a11e
@ -499,6 +499,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
|
|||||||
int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width);
|
int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width);
|
||||||
int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width);
|
int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width);
|
||||||
BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ );
|
BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ );
|
||||||
|
BLOCKTYPE BlockBelow = NextChunk->GetBlock( RelBlockX, BlockY - 1, RelBlockZ );
|
||||||
if (!g_BlockIsSolid[BlockIn]) // Making sure we are not inside a solid block
|
if (!g_BlockIsSolid[BlockIn]) // Making sure we are not inside a solid block
|
||||||
{
|
{
|
||||||
if (m_bOnGround) // check if it's still on the ground
|
if (m_bOnGround) // check if it's still on the ground
|
||||||
@ -540,13 +541,21 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Friction
|
if (
|
||||||
if (NextSpeed.SqrLength() > 0.0004f)
|
(BlockBelow != E_BLOCK_RAIL) &&
|
||||||
|
(BlockBelow != E_BLOCK_DETECTOR_RAIL) &&
|
||||||
|
(BlockBelow != E_BLOCK_POWERED_RAIL) &&
|
||||||
|
(BlockBelow != E_BLOCK_ACTIVATOR_RAIL)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
NextSpeed.x *= 0.7f/(1+a_Dt);
|
//Friction
|
||||||
if ( fabs(NextSpeed.x) < 0.05 ) NextSpeed.x = 0;
|
if (NextSpeed.SqrLength() > 0.0004f)
|
||||||
NextSpeed.z *= 0.7f/(1+a_Dt);
|
{
|
||||||
if ( fabs(NextSpeed.z) < 0.05 ) NextSpeed.z = 0;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,20 +88,19 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
SpeedY = 0; // Don't move vertically as on ground
|
SpeedY = 0; // Don't move vertically as on ground
|
||||||
|
|
||||||
// Set Y as current Y rounded up to bypass friction
|
// Set Y as current Y rounded up to bypass friction
|
||||||
// TODO: this causes positioning mismatches on the client, but Entity physics insists on friction!
|
SetPosY(floor(GetPosY()));
|
||||||
SetPosY(ceil(GetPosY()) + 0.05);
|
|
||||||
|
|
||||||
if (SpeedZ != 0) // Don't do anything if cart is stationary
|
if (SpeedZ != 0) // Don't do anything if cart is stationary
|
||||||
{
|
{
|
||||||
if (SpeedZ > 0)
|
if (SpeedZ > 0)
|
||||||
{
|
{
|
||||||
// Going SOUTH, slow down
|
// Going SOUTH, slow down
|
||||||
SpeedZ = SpeedZ - 0.05;
|
SpeedZ = SpeedZ - 0.1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Going NORTH, slow down
|
// Going NORTH, slow down
|
||||||
SpeedZ = SpeedZ + 0.05;
|
SpeedZ = SpeedZ + 0.1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -110,17 +109,17 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
case E_RAIL_XM_XP:
|
case E_RAIL_XM_XP:
|
||||||
{
|
{
|
||||||
SpeedY = 0;
|
SpeedY = 0;
|
||||||
SetPosY(ceil(GetPosY()) + 0.05);
|
SetPosY(floor(GetPosY()));
|
||||||
|
|
||||||
if (SpeedX != 0)
|
if (SpeedX != 0)
|
||||||
{
|
{
|
||||||
if (SpeedX > 0)
|
if (SpeedX > 0)
|
||||||
{
|
{
|
||||||
SpeedX = SpeedX - 0.05;
|
SpeedX = SpeedX - 0.1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SpeedX = SpeedX + 0.05;
|
SpeedX = SpeedX + 0.1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -131,21 +130,21 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
if (SpeedZ >= 0)
|
if (SpeedZ >= 0)
|
||||||
{
|
{
|
||||||
// SpeedZ POSITIVE, going SOUTH
|
// SpeedZ POSITIVE, going SOUTH
|
||||||
if (SpeedZ <= 6) // Speed limit of 6 SOUTH (m/s??)
|
if (SpeedZ <= 8) // Speed limit of 8 SOUTH (m/s??)
|
||||||
{
|
{
|
||||||
SpeedZ = SpeedZ + 1; // Speed up
|
SpeedZ = SpeedZ + 0.5; // Speed up
|
||||||
SpeedY = (0 - SpeedZ); // Downward movement is negative (0 minus positive numbers is negative)
|
SpeedY = (0 - SpeedZ); // Downward movement is negative (0 minus positive numbers is negative)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SpeedZ = 6; // Enforce speed limit
|
SpeedZ = 8; // Enforce speed limit
|
||||||
SpeedY = (0 - SpeedZ);
|
SpeedY = (0 - SpeedZ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// SpeedZ NEGATIVE, going NORTH
|
// SpeedZ NEGATIVE, going NORTH
|
||||||
SpeedZ = SpeedZ + 0.1; // Slow down
|
SpeedZ = SpeedZ + 0.6; // Slow down
|
||||||
SpeedY = (0 - SpeedZ); // Upward movement is positive (0 minus negative number is positive number)
|
SpeedY = (0 - SpeedZ); // Upward movement is positive (0 minus negative number is positive number)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -156,20 +155,20 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
if (SpeedX > 0)
|
if (SpeedX > 0)
|
||||||
{
|
{
|
||||||
// SpeedZ POSITIVE, going SOUTH
|
// SpeedZ POSITIVE, going SOUTH
|
||||||
SpeedZ = SpeedZ - 0.1; // Slow down
|
SpeedZ = SpeedZ - 0.6; // Slow down
|
||||||
SpeedY = SpeedZ; // Upward movement positive
|
SpeedY = SpeedZ; // Upward movement positive
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (SpeedZ >= -6) // Speed limit of 6 WEST (m/s??)
|
if (SpeedZ >= -8) // Speed limit of 8 WEST (m/s??)
|
||||||
{
|
{
|
||||||
// SpeedZ NEGATIVE, going NORTH
|
// SpeedZ NEGATIVE, going NORTH
|
||||||
SpeedZ = SpeedZ - 1; // Speed up
|
SpeedZ = SpeedZ - 0.5; // Speed up
|
||||||
SpeedY = SpeedZ; // Downward movement negative
|
SpeedY = SpeedZ; // Downward movement negative
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SpeedZ = 6; // Enforce speed limit
|
SpeedZ = 8; // Enforce speed limit
|
||||||
SpeedY = SpeedZ;
|
SpeedY = SpeedZ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,20 +179,20 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
{
|
{
|
||||||
if (SpeedX >= 0)
|
if (SpeedX >= 0)
|
||||||
{
|
{
|
||||||
if (SpeedX <= 6)
|
if (SpeedX <= 8)
|
||||||
{
|
{
|
||||||
SpeedX = SpeedX + 1;
|
SpeedX = SpeedX + 0.5;
|
||||||
SpeedY = (0 - SpeedX);
|
SpeedY = (0 - SpeedX);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SpeedX = 6;
|
SpeedX = 8;
|
||||||
SpeedY = (0 - SpeedX);
|
SpeedY = (0 - SpeedX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SpeedX = SpeedX + 0.1;
|
SpeedX = SpeedX + 0.6;
|
||||||
SpeedY = (0 - SpeedX);
|
SpeedY = (0 - SpeedX);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -203,19 +202,19 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
{
|
{
|
||||||
if (SpeedX > 0)
|
if (SpeedX > 0)
|
||||||
{
|
{
|
||||||
SpeedX = SpeedX - 0.1;
|
SpeedX = SpeedX - 0.6;
|
||||||
SpeedY = SpeedX;
|
SpeedY = SpeedX;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (SpeedX >= -6)
|
if (SpeedX >= -8)
|
||||||
{
|
{
|
||||||
SpeedX = SpeedX - 1;
|
SpeedX = SpeedX - 0.5;
|
||||||
SpeedY = SpeedX;
|
SpeedY = SpeedX;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SpeedX = -6;
|
SpeedX = -8;
|
||||||
SpeedY = SpeedX;
|
SpeedY = SpeedX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user