From 3300cfe491297b284096d976c83fb7a1107162e9 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 4 Sep 2013 17:52:15 +0100 Subject: Added better push out of entities --- source/Entities/Entity.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source/Entities') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 56fd36a05..7e118c74e 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -517,7 +517,14 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } else { - // Push out entity. + //Push out entity. + + if (NextChunk->GetBlock( RelBlockX + 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += 0.2; } + else if (NextChunk->GetBlock( RelBlockX - 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += -0.2; } + else if (NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ + 1 ) == E_BLOCK_AIR) { NextPos.z += 0.2; } + else if (NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ - 1 ) == E_BLOCK_AIR) { NextPos.z += -0.2; } + else { NextPos.y += 0.2; } + m_bOnGround = true; NextPos.y += 0.2; LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}", -- cgit v1.2.3 From fd35f6d70764626ddc7cfd49b0fb8a7f3e4149ab Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 4 Sep 2013 18:13:46 +0100 Subject: Pickups are a little less jittery They also spawn closer to player mouth. --- source/Entities/Pickup.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Pickup.cpp b/source/Entities/Pickup.cpp index 9b388366a..ef1581c1a 100644 --- a/source/Entities/Pickup.cpp +++ b/source/Entities/Pickup.cpp @@ -25,7 +25,7 @@ cPickup::cPickup(int a_MicroPosX, int a_MicroPosY, int a_MicroPosZ, const cItem & a_Item, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) - : cEntity(etPickup, ((double)(a_MicroPosX)) / 32, ((double)(a_MicroPosY)) / 32, ((double)(a_MicroPosZ)) / 32, 0.2, 0.2) + : cEntity(etPickup, (((double)(a_MicroPosX)) / 32) + 0.1 /*Accomodate player vomiting*/, ((double)(a_MicroPosY)) / 32, ((double)(a_MicroPosZ)) / 32, 0.2, 0.2) , m_Timer( 0.f ) , m_Item(a_Item) , m_bCollected( false ) @@ -33,7 +33,7 @@ cPickup::cPickup(int a_MicroPosX, int a_MicroPosY, int a_MicroPosZ, const cItem m_MaxHealth = 5; m_Health = 5; SetSpeed(a_SpeedX, a_SpeedY, a_SpeedZ); - m_Gravity = -3.0; + m_Gravity = -10.0; } -- cgit v1.2.3 From 6059c44dcba28bf6f3f29893322715c9c2dbe249 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 4 Sep 2013 18:15:20 +0100 Subject: Players toss a little further --- source/Entities/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/Entities') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index 0943f61ff..8356d588e 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -1182,7 +1182,7 @@ void cPlayer::TossItem( double vX = 0, vY = 0, vZ = 0; EulerToVector(-GetRotation(), GetPitch(), vZ, vX, vY); vY = -vY * 2 + 1.f; - m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY() + 1.6f, GetPosZ(), vX * 2, vY * 2, vZ * 2); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY() + 1.6f, GetPosZ(), vX * 3, vY * 3, vZ * 3); } -- cgit v1.2.3 From ad89a0d460cc6afdc5a433695861cd0bf3ebeadd Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 4 Sep 2013 18:26:00 +0100 Subject: Pickups spawn with correct speed and position Added a comment-space as well. --- source/Entities/Entity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/Entities') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 7e118c74e..8388bf092 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -517,7 +517,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } else { - //Push out entity. + // Push out entity. if (NextChunk->GetBlock( RelBlockX + 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += 0.2; } else if (NextChunk->GetBlock( RelBlockX - 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += -0.2; } -- cgit v1.2.3 From 178b5884fc8cb4d58ed89868da55e1d241d8d1a9 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 5 Sep 2013 21:41:47 +0100 Subject: Further physics improvements [SEE DESC] This was mainly focused on pickups, but it works for other things too. * Entities no longer clip through blocks positive-vertically (this fixes pickup issues as well). * Entities lie flat against a block when they hit it. * Reduced entity (mainly pickup) block clipping in non vertical directions. --- source/Entities/Entity.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 8388bf092..a74f80058 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -519,17 +519,16 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { // Push out entity. - if (NextChunk->GetBlock( RelBlockX + 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += 0.2; } - else if (NextChunk->GetBlock( RelBlockX - 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += -0.2; } - else if (NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ + 1 ) == E_BLOCK_AIR) { NextPos.z += 0.2; } - else if (NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ - 1 ) == E_BLOCK_AIR) { NextPos.z += -0.2; } - else { NextPos.y += 0.2; } - + if (NextChunk->GetBlock( RelBlockX + 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += 0.2; NextPos.z, NextPos.y = 0; } + else if (NextChunk->GetBlock( RelBlockX - 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += -0.2; NextPos.z, NextPos.y = 0; } + else if (NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ + 1 ) == E_BLOCK_AIR) { NextPos.z += 0.2; NextPos.x, NextPos.y = 0; } + else if (NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ - 1 ) == E_BLOCK_AIR) { NextPos.z += -0.2; NextPos.x, NextPos.y = 0; } + else { NextPos.y += 0.2; NextPos.z, NextPos.x = 0;} + m_bOnGround = true; - NextPos.y += 0.2; - LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}", - m_UniqueID, GetClass(), BlockX, BlockY, BlockZ - ); + + LOGD("Entity #%d (%s) is inside a block at {%d,%d,%d}", + m_UniqueID, GetClass(), BlockX, BlockY, BlockZ); } if (!m_bOnGround) @@ -647,8 +646,9 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } } NextPos.Set(Tracer.RealHit.x,Tracer.RealHit.y,Tracer.RealHit.z); - NextPos.x += Tracer.HitNormal.x * 0.5f; - NextPos.z += Tracer.HitNormal.z * 0.5f; + NextPos.x += Tracer.HitNormal.x * 0.3f; + NextPos.y += Tracer.HitNormal.y * 0.1f; // Any larger produces entity vibration-upon-the-spot + NextPos.z += Tracer.HitNormal.z * 0.3f; } else NextPos += (NextSpeed * a_Dt); -- cgit v1.2.3 From 35efe9c72739b37773439c257c301e5fee22ada7 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 7 Sep 2013 21:42:33 +0100 Subject: Fixed formatting and removed gravity thing --- source/Entities/Entity.cpp | 3 ++- source/Entities/Pickup.cpp | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index a74f80058..0298ca960 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -528,7 +528,8 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) m_bOnGround = true; LOGD("Entity #%d (%s) is inside a block at {%d,%d,%d}", - m_UniqueID, GetClass(), BlockX, BlockY, BlockZ); + m_UniqueID, GetClass(), BlockX, BlockY, + ); } if (!m_bOnGround) diff --git a/source/Entities/Pickup.cpp b/source/Entities/Pickup.cpp index ef1581c1a..db7be8b04 100644 --- a/source/Entities/Pickup.cpp +++ b/source/Entities/Pickup.cpp @@ -33,7 +33,6 @@ cPickup::cPickup(int a_MicroPosX, int a_MicroPosY, int a_MicroPosZ, const cItem m_MaxHealth = 5; m_Health = 5; SetSpeed(a_SpeedX, a_SpeedY, a_SpeedZ); - m_Gravity = -10.0; } -- cgit v1.2.3 From 57c17a02dba12011bb776280b55fc9eb93bee186 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 9 Sep 2013 18:55:42 +0100 Subject: A few Minecart fixes * Removed unneeded flatrail setpos * Fixed health checking --- source/Entities/Minecart.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Minecart.cpp b/source/Entities/Minecart.cpp index 0c0b7b58a..f633206a2 100644 --- a/source/Entities/Minecart.cpp +++ b/source/Entities/Minecart.cpp @@ -105,9 +105,6 @@ void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) SpeedY = 0; // Don't move vertically as on ground SpeedX = 0; // Correct diagonal movement from curved rails - // Set Y as current Y rounded up to bypass friction - SetPosY(floor(GetPosY())); - if (SpeedZ != 0) // Don't do anything if cart is stationary { if (SpeedZ > 0) @@ -130,8 +127,6 @@ void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) SpeedY = 0; SpeedZ = 0; - SetPosY(floor(GetPosY())); - if (SpeedX != 0) { if (SpeedX > 0) @@ -347,7 +342,7 @@ void cMinecart::DoTakeDamage(TakeDamageInfo & TDI) { super::DoTakeDamage(TDI); - if (GetHealth() == 0) + if (GetHealth() <= 0) { Destroy(true); } -- cgit v1.2.3 From 277b26b4c23e6c68190ca435f36c4a6e2995c058 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 11 Sep 2013 18:51:27 +0100 Subject: Fixed two bugs --- source/Entities/Entity.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 0298ca960..b8596927f 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -519,11 +519,11 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { // Push out entity. - if (NextChunk->GetBlock( RelBlockX + 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += 0.2; NextPos.z, NextPos.y = 0; } - else if (NextChunk->GetBlock( RelBlockX - 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += -0.2; NextPos.z, NextPos.y = 0; } - else if (NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ + 1 ) == E_BLOCK_AIR) { NextPos.z += 0.2; NextPos.x, NextPos.y = 0; } - else if (NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ - 1 ) == E_BLOCK_AIR) { NextPos.z += -0.2; NextPos.x, NextPos.y = 0; } - else { NextPos.y += 0.2; NextPos.z, NextPos.x = 0;} + if (NextChunk->GetBlock( RelBlockX + 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += 0.2; } + else if (NextChunk->GetBlock( RelBlockX - 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += -0.2; } + else if (NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ + 1 ) == E_BLOCK_AIR) { NextPos.z += 0.2; } + else if (NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ - 1 ) == E_BLOCK_AIR) { NextPos.z += -0.2; } + else { NextPos.y += 0.2; } m_bOnGround = true; @@ -648,7 +648,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } NextPos.Set(Tracer.RealHit.x,Tracer.RealHit.y,Tracer.RealHit.z); NextPos.x += Tracer.HitNormal.x * 0.3f; - NextPos.y += Tracer.HitNormal.y * 0.1f; // Any larger produces entity vibration-upon-the-spot + NextPos.y += Tracer.HitNormal.y * 0.05f; // Any larger produces entity vibration-upon-the-spot NextPos.z += Tracer.HitNormal.z * 0.3f; } else -- cgit v1.2.3 From a1d5d25525bec8ed7646e887a08bae48e84f9131 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 11 Sep 2013 22:10:29 +0100 Subject: Implemented xoft's suggestions I totally didn't copy this from the fire simulator... (I did, but I changed it quite a bit :P) --- source/Entities/Entity.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index b8596927f..3cb53a6c6 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -518,13 +518,30 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) else { // Push out entity. + BLOCKTYPE GotBlock; - if (NextChunk->GetBlock( RelBlockX + 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += 0.2; } - else if (NextChunk->GetBlock( RelBlockX - 1, BlockY, RelBlockZ ) == E_BLOCK_AIR) { NextPos.x += -0.2; } - else if (NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ + 1 ) == E_BLOCK_AIR) { NextPos.z += 0.2; } - else if (NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ - 1 ) == E_BLOCK_AIR) { NextPos.z += -0.2; } - else { NextPos.y += 0.2; } + static const struct + { + int x, y, z; + } gCrossCoords[] = + { + { 1, 0, 0}, + {-1, 0, 0}, + { 0, 0, 1}, + { 0, 0, -1}, + } ; + for (int i = 0; i < ARRAYCOUNT(gCrossCoords); i++) + { + NextChunk->UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock); + if (GotBlock == E_BLOCK_AIR) + { + NextPos.x += gCrossCoords[i].x; + NextPos.z += gCrossCoords[i].z; + } + else { NextPos.y += 0.2; } + } // for i - gCrossCoords[] + m_bOnGround = true; LOGD("Entity #%d (%s) is inside a block at {%d,%d,%d}", -- cgit v1.2.3 From 8163ca954910d615b260d62881a06b45c9b7d05c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 12 Sep 2013 10:25:13 +0100 Subject: Implemented xoft's suggestions again --- source/Entities/Entity.cpp | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 3cb53a6c6..4d7206965 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -1,4 +1,3 @@ - #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Entity.h" @@ -520,27 +519,25 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) // Push out entity. BLOCKTYPE GotBlock; - static const struct - { - int x, y, z; - } gCrossCoords[] = + static const Vector3i CrossCoords[] = { - { 1, 0, 0}, - {-1, 0, 0}, - { 0, 0, 1}, - { 0, 0, -1}, + Vector3i(1, 0, 0), + Vector3i(-1, 0, 0), + Vector3i(0, 0, 1), + Vector3i(0, 0, -1), } ; - - for (int i = 0; i < ARRAYCOUNT(gCrossCoords); i++) + Vector3i PushDirection(0, 1, 0); + + for (int i = 0; i < ARRAYCOUNT(CrossCoords); i++) { - NextChunk->UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock); - if (GotBlock == E_BLOCK_AIR) - { - NextPos.x += gCrossCoords[i].x; - NextPos.z += gCrossCoords[i].z; - } - else { NextPos.y += 0.2; } - } // for i - gCrossCoords[] + NextChunk->UnboundedRelGetBlockType(RelBlockX + CrossCoords[i].x, BlockY, RelBlockZ + CrossCoords[i].z, GotBlock); + if (!g_BlockIsSolid[GotBlock]) + { + PushDirection = CrossCoords[i]; + break; + } + } // for i - CrossCoords[] + NextPos += Vector3d(PushDirection) * 0.2; m_bOnGround = true; -- cgit v1.2.3 From a39564a46aee5a34157733decb8ef79cd110e82d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 12 Sep 2013 23:31:26 +0100 Subject: Fixed water speed issues --- source/Entities/Entity.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 4d7206965..2443b1810 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -607,19 +607,19 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) switch(WaterDir) { case X_PLUS: - m_WaterSpeed.x = 1.f; + m_WaterSpeed.x = 0.2f; m_bOnGround = false; break; case X_MINUS: - m_WaterSpeed.x = -1.f; + m_WaterSpeed.x = -0.2f; m_bOnGround = false; break; case Z_PLUS: - m_WaterSpeed.z = 1.f; + m_WaterSpeed.z = 0.2f; m_bOnGround = false; break; case Z_MINUS: - m_WaterSpeed.z = -1.f; + m_WaterSpeed.z = -0.2f; m_bOnGround = false; break; @@ -650,7 +650,6 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { if( Ret == 1 ) { - if( Tracer.HitNormal.x != 0.f ) NextSpeed.x = 0.f; if( Tracer.HitNormal.y != 0.f ) NextSpeed.y = 0.f; if( Tracer.HitNormal.z != 0.f ) NextSpeed.z = 0.f; @@ -666,7 +665,9 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) NextPos.z += Tracer.HitNormal.z * 0.3f; } else + { NextPos += (NextSpeed * a_Dt); + } } else { -- cgit v1.2.3 From 22b8f3a2e0d46b36658fd46fc3e14af85b9dfe45 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 12 Sep 2013 23:57:02 +0100 Subject: Even more fixes [SEE DESC] * Fixed minecarts breaking completely due to stuff * Rails are now non solid again + Added IsRail inline bool - Removed Herobrine --- source/Entities/Entity.cpp | 49 +++++++++++++++++++++++++++++++------------- source/Entities/Minecart.cpp | 20 ++++++++++-------- source/Entities/Minecart.h | 14 +++++++++++++ 3 files changed, 61 insertions(+), 22 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 2443b1810..d884fe51c 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -12,6 +12,7 @@ #include "../Simulator/FluidSimulator.h" #include "../PluginManager.h" #include "../Tracer.h" +#include "Minecart.h" @@ -553,6 +554,11 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water. } + else if ((IsBlockRail(BlockBelow)) && (IsMinecart())) // Rails aren't solid, except for Minecarts + { + fallspeed = 0; + m_bOnGround = true; + } else if (BlockIn == E_BLOCK_COBWEB) { NextSpeed.y *= 0.05; // Reduce overall falling speed @@ -567,25 +573,40 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } else { - if ( - (BlockBelow != E_BLOCK_RAIL) && - (BlockBelow != E_BLOCK_DETECTOR_RAIL) && - (BlockBelow != E_BLOCK_POWERED_RAIL) && - (BlockBelow != E_BLOCK_ACTIVATOR_RAIL) - ) + if (IsMinecart()) { - // Friction - if (NextSpeed.SqrLength() > 0.0004f) + if (!IsBlockRail(BlockBelow)) { - NextSpeed.x *= 0.7f / (1 + a_Dt); - if (fabs(NextSpeed.x) < 0.05) + // Friction if minecart is off track, otherwise, Minecart.cpp handles this + if (NextSpeed.SqrLength() > 0.0004f) { - NextSpeed.x = 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; + } } - NextSpeed.z *= 0.7f / (1 + a_Dt); - if (fabs(NextSpeed.z) < 0.05) + } + else + { + // Friction + if (NextSpeed.SqrLength() > 0.0004f) { - 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; + } } } } diff --git a/source/Entities/Minecart.cpp b/source/Entities/Minecart.cpp index f633206a2..a2f1e5593 100644 --- a/source/Entities/Minecart.cpp +++ b/source/Entities/Minecart.cpp @@ -54,20 +54,24 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) if ((GetPosY() > 0) && (GetPosY() < cChunkDef::Height)) { BLOCKTYPE BelowType = GetWorld()->GetBlock(floor(GetPosX()), floor(GetPosY() -1 ), floor(GetPosZ())); + BLOCKTYPE InsideType = GetWorld()->GetBlock(floor(GetPosX()), floor(GetPosY()), floor(GetPosZ())); - if ( - (BelowType == E_BLOCK_RAIL) || - (BelowType == E_BLOCK_POWERED_RAIL) || - (BelowType == E_BLOCK_DETECTOR_RAIL) || - (BelowType == E_BLOCK_ACTIVATOR_RAIL) - ) + if (IsBlockRail(BelowType)) { HandleRailPhysics(a_Dt, a_Chunk); } else { - super::HandlePhysics(a_Dt, a_Chunk); - BroadcastMovementUpdate(); + if (IsBlockRail(InsideType)) + { + SetPosY(ceil(GetPosY())); + HandleRailPhysics(a_Dt, a_Chunk); + } + else + { + super::HandlePhysics(a_Dt, a_Chunk); + BroadcastMovementUpdate(); + } } } else diff --git a/source/Entities/Minecart.h b/source/Entities/Minecart.h index f98b02bb5..0ca6586db 100644 --- a/source/Entities/Minecart.h +++ b/source/Entities/Minecart.h @@ -16,6 +16,20 @@ +inline bool IsBlockRail(BLOCKTYPE a_BlockType) + { + return ( + (a_BlockType == E_BLOCK_RAIL) || + (a_BlockType == E_BLOCK_ACTIVATOR_RAIL) || + (a_BlockType == E_BLOCK_DETECTOR_RAIL) || + (a_BlockType == E_BLOCK_POWERED_RAIL) + ) ; + } + + + + + class cMinecart : public cEntity { -- cgit v1.2.3 From 47119b30270b0ea8e958bc64c38f27df47a9ae5d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 13 Sep 2013 19:54:50 +0100 Subject: Even better pickup physics --- source/Entities/Entity.cpp | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index d884fe51c..3a93b7519 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -520,31 +520,36 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) // Push out entity. BLOCKTYPE GotBlock; - static const Vector3i CrossCoords[] = + static const struct { - Vector3i(1, 0, 0), - Vector3i(-1, 0, 0), - Vector3i(0, 0, 1), - Vector3i(0, 0, -1), + int x, y, z; + } gCrossCoords[] = + { + { 1, 0, 0}, + {-1, 0, 0}, + { 0, 0, 1}, + { 0, 0, -1}, } ; - Vector3i PushDirection(0, 1, 0); - - for (int i = 0; i < ARRAYCOUNT(CrossCoords); i++) + + bool IsNoAirSurrounding = true; + for (int i = 0; i < ARRAYCOUNT(gCrossCoords); i++) { - NextChunk->UnboundedRelGetBlockType(RelBlockX + CrossCoords[i].x, BlockY, RelBlockZ + CrossCoords[i].z, GotBlock); - if (!g_BlockIsSolid[GotBlock]) - { - PushDirection = CrossCoords[i]; - break; - } - } // for i - CrossCoords[] - NextPos += Vector3d(PushDirection) * 0.2; + NextChunk->UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock); + if (!g_BlockIsSolid[GotBlock]) + { + NextPos.x += gCrossCoords[i].x; + NextPos.z += gCrossCoords[i].z; + IsNoAirSurrounding = false; + } + } // for i - gCrossCoords[] + if (IsNoAirSurrounding) + { NextPos.y += 0.5; } + m_bOnGround = true; LOGD("Entity #%d (%s) is inside a block at {%d,%d,%d}", - m_UniqueID, GetClass(), BlockX, BlockY, - ); + m_UniqueID, GetClass(), BlockX, BlockY, BlockZ); } if (!m_bOnGround) -- cgit v1.2.3 From 11bbfbc98acc80c72daacfcc0bea404fdce1748c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 15 Sep 2013 12:15:27 +0100 Subject: Added break --- source/Entities/Entity.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'source/Entities') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 3a93b7519..e79b441f3 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -540,6 +540,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) NextPos.x += gCrossCoords[i].x; NextPos.z += gCrossCoords[i].z; IsNoAirSurrounding = false; + break; } } // for i - gCrossCoords[] -- cgit v1.2.3