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/Entity.cpp') 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 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/Entity.cpp') 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/Entity.cpp') 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 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/Entities/Entity.cpp') 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) -- 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/Entity.cpp') 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/Entity.cpp') 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/Entity.cpp') 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/Entity.cpp') 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 +++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'source/Entities/Entity.cpp') 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; + } } } } -- 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/Entity.cpp') 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/Entity.cpp') 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