From 67e8f7531809f48bad7dd92bc6f28f63bd7cbd21 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 6 Sep 2013 00:04:49 +0200 Subject: Implemented SteerVehicle packet. --- source/Entities/Entity.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'source/Entities/Entity.cpp') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 56fd36a05..4066e81ab 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -546,22 +546,24 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } else { + // TODO: This condition belongs to minecarts, without it, they derails too much. + // But it shouldn't be here for other entities. We need a complete minecart physics overhaul. if ( - (BlockBelow != E_BLOCK_RAIL) && - (BlockBelow != E_BLOCK_DETECTOR_RAIL) && - (BlockBelow != E_BLOCK_POWERED_RAIL) && + (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) { - NextSpeed.x *= 0.7f / (1 + a_Dt); + NextSpeed.x *= 0.6666; if (fabs(NextSpeed.x) < 0.05) { NextSpeed.x = 0; } - NextSpeed.z *= 0.7f / (1 + a_Dt); + NextSpeed.z *= 0.6666; if (fabs(NextSpeed.z) < 0.05) { NextSpeed.z = 0; @@ -1225,6 +1227,25 @@ void cEntity::AddSpeedZ(double a_AddSpeedZ) +void cEntity::SteerVehicle(float a_Forward, float a_Sideways) +{ + if (m_AttachedTo == NULL) + { + return; + } + if ((a_Forward != 0) || (a_Sideways != 0)) + { + Vector3d LookVector = GetLookVector(); + double AddSpeedX = LookVector.x * a_Forward + LookVector.z * a_Sideways; + double AddSpeedZ = LookVector.z * a_Forward - LookVector.x * a_Sideways; + m_AttachedTo->AddSpeed(AddSpeedX, 0, AddSpeedZ); + } +} + + + + + ////////////////////////////////////////////////////////////////////////// // Get look vector (this is NOT a rotation!) Vector3d cEntity::GetLookVector(void) const -- cgit v1.2.3