Fixed disappearing pickups - wrong physics simulation.
FS #285 git-svn-id: http://mc-server.googlecode.com/svn/trunk@1125 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
8be0b4d113
commit
8798c529d2
@ -103,12 +103,13 @@ void cPickup::HandlePhysics(float a_Dt)
|
||||
m_ResultingSpeed.Set(0.f, 0.f, 0.f);
|
||||
cWorld * World = GetWorld();
|
||||
|
||||
a_Dt /= 1000; // Go from msec to sec, so that physics formulas work
|
||||
|
||||
if (m_bOnGround) // check if it's still on the ground
|
||||
{
|
||||
int BlockX = (m_Pos.x)<0 ? (int)m_Pos.x-1 : (int)m_Pos.x;
|
||||
int BlockZ = (m_Pos.z)<0 ? (int)m_Pos.z-1 : (int)m_Pos.z;
|
||||
int BlockX = (m_Pos.x < 0) ? (int)m_Pos.x - 1 : (int)m_Pos.x;
|
||||
int BlockZ = (m_Pos.z < 0) ? (int)m_Pos.z - 1 : (int)m_Pos.z;
|
||||
char BlockBelow = World->GetBlock(BlockX, (int)m_Pos.y - 1, BlockZ);
|
||||
//Not only air, falls through water ;)
|
||||
if (BlockBelow == E_BLOCK_AIR || IsBlockWater(BlockBelow))
|
||||
{
|
||||
m_bOnGround = false;
|
||||
@ -166,22 +167,31 @@ void cPickup::HandlePhysics(float a_Dt)
|
||||
|
||||
m_ResultingSpeed += m_WaterSpeed;
|
||||
|
||||
|
||||
if (!m_bOnGround)
|
||||
{
|
||||
|
||||
float Gravity = -9.81f * a_Dt;
|
||||
if (Gravity < -3) // Cap gravity-caused speed at 3 m / sec
|
||||
{
|
||||
Gravity = -3;
|
||||
}
|
||||
m_Speed.y += Gravity;
|
||||
|
||||
// Set to hit position
|
||||
m_ResultingSpeed += m_Speed;
|
||||
|
||||
/*
|
||||
LOGD("Pickup #%d speed: {%.03f, %.03f, %.03f}, pos {%.02f, %.02f, %.02f}",
|
||||
m_UniqueID,
|
||||
m_ResultingSpeed.x, m_ResultingSpeed.y, m_ResultingSpeed.z,
|
||||
m_Pos.x, m_Pos.y, m_Pos.z
|
||||
);
|
||||
*/
|
||||
|
||||
cTracer Tracer(GetWorld());
|
||||
int Ret = Tracer.Trace(m_Pos, m_Speed, 2);
|
||||
if (Ret) // Oh noez! we hit something
|
||||
{
|
||||
|
||||
|
||||
if ((Tracer.RealHit - Vector3f(m_Pos)).SqrLength() <= ( m_ResultingSpeed * a_Dt ).SqrLength())
|
||||
{
|
||||
m_bReplicated = false; // It's only interesting to replicate when we actually hit something...
|
||||
@ -210,7 +220,7 @@ void cPickup::HandlePhysics(float a_Dt)
|
||||
}
|
||||
}
|
||||
// Usable for debugging
|
||||
//SetPosition(m_Pos.x, m_Pos.y, m_Pos.z);
|
||||
SetPosition(m_Pos.x, m_Pos.y, m_Pos.z);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user