1
0

Physics enhancements

Minecarts no longer glitch on flat rails
Improved acceleration, speed limit, and stopping
This commit is contained in:
Tiger Wang 2013-08-29 15:25:12 +01:00
parent 9f59b9a093
commit acaae7a11e
2 changed files with 37 additions and 29 deletions

View File

@ -499,6 +499,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width);
int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width);
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 (m_bOnGround) // check if it's still on the ground
@ -539,6 +540,13 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
NextSpeed.y += fallspeed;
}
else
{
if (
(BlockBelow != E_BLOCK_RAIL) &&
(BlockBelow != E_BLOCK_DETECTOR_RAIL) &&
(BlockBelow != E_BLOCK_POWERED_RAIL) &&
(BlockBelow != E_BLOCK_ACTIVATOR_RAIL)
)
{
//Friction
if (NextSpeed.SqrLength() > 0.0004f)
@ -549,6 +557,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
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
//might have different speed modifiers according to terrain.

View File

@ -88,20 +88,19 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk)
SpeedY = 0; // Don't move vertically as on ground
// 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(ceil(GetPosY()) + 0.05);
SetPosY(floor(GetPosY()));
if (SpeedZ != 0) // Don't do anything if cart is stationary
{
if (SpeedZ > 0)
{
// Going SOUTH, slow down
SpeedZ = SpeedZ - 0.05;
SpeedZ = SpeedZ - 0.1;
}
else
{
// Going NORTH, slow down
SpeedZ = SpeedZ + 0.05;
SpeedZ = SpeedZ + 0.1;
}
}
break;
@ -110,17 +109,17 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk)
case E_RAIL_XM_XP:
{
SpeedY = 0;
SetPosY(ceil(GetPosY()) + 0.05);
SetPosY(floor(GetPosY()));
if (SpeedX != 0)
{
if (SpeedX > 0)
{
SpeedX = SpeedX - 0.05;
SpeedX = SpeedX - 0.1;
}
else
{
SpeedX = SpeedX + 0.05;
SpeedX = SpeedX + 0.1;
}
}
break;
@ -131,21 +130,21 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk)
if (SpeedZ >= 0)
{
// 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)
}
else
{
SpeedZ = 6; // Enforce speed limit
SpeedZ = 8; // Enforce speed limit
SpeedY = (0 - SpeedZ);
}
}
else
{
// 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)
}
break;
@ -156,20 +155,20 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk)
if (SpeedX > 0)
{
// SpeedZ POSITIVE, going SOUTH
SpeedZ = SpeedZ - 0.1; // Slow down
SpeedZ = SpeedZ - 0.6; // Slow down
SpeedY = SpeedZ; // Upward movement positive
}
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 = SpeedZ - 1; // Speed up
SpeedZ = SpeedZ - 0.5; // Speed up
SpeedY = SpeedZ; // Downward movement negative
}
else
{
SpeedZ = 6; // Enforce speed limit
SpeedZ = 8; // Enforce speed limit
SpeedY = SpeedZ;
}
}
@ -180,20 +179,20 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk)
{
if (SpeedX >= 0)
{
if (SpeedX <= 6)
if (SpeedX <= 8)
{
SpeedX = SpeedX + 1;
SpeedX = SpeedX + 0.5;
SpeedY = (0 - SpeedX);
}
else
{
SpeedX = 6;
SpeedX = 8;
SpeedY = (0 - SpeedX);
}
}
else
{
SpeedX = SpeedX + 0.1;
SpeedX = SpeedX + 0.6;
SpeedY = (0 - SpeedX);
}
break;
@ -203,19 +202,19 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk)
{
if (SpeedX > 0)
{
SpeedX = SpeedX - 0.1;
SpeedX = SpeedX - 0.6;
SpeedY = SpeedX;
}
else
{
if (SpeedX >= -6)
if (SpeedX >= -8)
{
SpeedX = SpeedX - 1;
SpeedX = SpeedX - 0.5;
SpeedY = SpeedX;
}
else
{
SpeedX = -6;
SpeedX = -8;
SpeedY = SpeedX;
}
}