summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorChristophe Piveteau <chripiveteau@gmail.com>2014-08-15 17:54:43 +0200
committerChristophe Piveteau <chripiveteau@gmail.com>2014-08-15 17:54:43 +0200
commit72c02ceb171949acd07338e77c8ee0d3439f8173 (patch)
treea05a1269a0bb29482b0f857a807ed3fa3710fa74 /src/Entities
parentClarify comment message (diff)
downloadcuberite-72c02ceb171949acd07338e77c8ee0d3439f8173.tar
cuberite-72c02ceb171949acd07338e77c8ee0d3439f8173.tar.gz
cuberite-72c02ceb171949acd07338e77c8ee0d3439f8173.tar.bz2
cuberite-72c02ceb171949acd07338e77c8ee0d3439f8173.tar.lz
cuberite-72c02ceb171949acd07338e77c8ee0d3439f8173.tar.xz
cuberite-72c02ceb171949acd07338e77c8ee0d3439f8173.tar.zst
cuberite-72c02ceb171949acd07338e77c8ee0d3439f8173.zip
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/Minecart.cpp66
1 files changed, 36 insertions, 30 deletions
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index 4753f720d..9420eca02 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -876,7 +876,10 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
// Prevent division by small numbers
- Distance.z = std::max(Distance.z, 0.001);
+ if (abs(Distance.z) < 0.001)
+ {
+ Distance.z = 0.001;
+ }
/* Check to which side the minecart is to be pushed.
Let's consider a z-x-coordinate system where the minecart is the center (0/0).
@@ -886,27 +889,27 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) ||
((Distance.z < 0) && ((Distance.x / Distance.z) <= 1))
)
- {
- if ((-GetSpeedX() * 0.4 / sqrt(2)) < 0.01)
- {
+ { // Moving -X + Z
+ if ((-GetSpeedX() * 0.4 / sqrt(2)) < 0.01) // ~ speedX >= 0
+ { // Immobile or not moving in the "right" direction. Give it a bump!
AddSpeedX(-4 / sqrt(2));
AddSpeedZ(4 / sqrt(2));
}
- else
- {
- SetSpeedX(-GetSpeedX() * 0.4);
- SetSpeedZ(GetSpeedZ() * 0.4);
+ else // ~ SpeedX < 0
+ { // Moving in the "right" direction. Only accelerate it a bit.
+ SetSpeedX(GetSpeedX() * 0.4 / sqrt(2));
+ SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2));
}
- }
- else if ((GetSpeedX() * 0.4 / sqrt(2)) < 0.01)
- {
+ } // Moving +X -Z
+ else if ((GetSpeedX() * 0.4 / sqrt(2)) < 0.01) // ~ SpeedX <= 0
+ { // Immobile or not moving in the "right" direction
AddSpeedX(4 / sqrt(2));
AddSpeedZ(-4 / sqrt(2));
}
- else
- {
- SetSpeedX(GetSpeedX() * 0.4);
- SetSpeedZ(-GetSpeedZ() * 0.4);
+ else // ~ SpeedX > 0
+ { // Moving in the "right" direction
+ SetSpeedX(GetSpeedX() * 0.4 / sqrt(2));
+ SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2));
}
break;
}
@@ -916,37 +919,40 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
// Prevent division by small numbers
- Distance.z = std::max(Distance.z, 0.001);
+ if (abs(Distance.z) < 0.001)
+ {
+ Distance.z = 0.001;
+ }
/* Check to which side the minecart is to be pushed.
Let's consider a z-x-coordinate system where the minecart is the center (0/0).
The minecart moves along the line x = z, the perpendicular line to this is x = -z.
In order to decide to which side the minecart is to be pushed, it must be checked on what side of the perpendicular line the pushing entity is located. */
- if (
+ if ( // Moving +X +Z
((Distance.z > 0) && ((Distance.x / Distance.z) <= -1)) ||
((Distance.z < 0) && ((Distance.x / Distance.z) >= -1))
)
{
- if ((GetSpeedX() * 0.4) < 0.01)
- {
+ if ((GetSpeedX() * 0.4) < 0.01) // ~ SpeedX <= 0
+ { // Immobile or not moving in the "right" direction
AddSpeedX(4 / sqrt(2));
AddSpeedZ(4 / sqrt(2));
}
- else
- {
- SetSpeedX(GetSpeedX() * 0.4);
- SetSpeedZ(GetSpeedZ() * 0.4);
+ else // SpeedX > 0
+ { // Moving in the "right" direction
+ SetSpeedX(GetSpeedX() * 0.4 / sqrt(2));
+ SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2));
}
- }
- else if ((-GetSpeedX() * 0.4) < 0.01)
- {
+ } // Moving -X -Z
+ else if ((-GetSpeedX() * 0.4) < 0.01) // ~ SpeedX >= 0
+ { // Immobile or not moving in the "right" direction
AddSpeedX(-4 / sqrt(2));
AddSpeedZ(-4 / sqrt(2));
}
- else
- {
- SetSpeedX(-GetSpeedX() * 0.4);
- SetSpeedZ(-GetSpeedZ() * 0.4);
+ else // ~ SpeedX < 0
+ { // Moving in the "right" direction
+ SetSpeedX(GetSpeedX() * 0.4 / sqrt(2));
+ SetSpeedZ(GetSpeedZ() * 0.4 / sqrt(2));
}
break;
}