From 4a197ba22af4eed01be632ea2dd7d103a963f043 Mon Sep 17 00:00:00 2001 From: Trisjdc Date: Sat, 12 Jul 2014 13:13:38 +0100 Subject: Core/PathGenerator: Split raycast paths into more points for better path z normalization. Solves many of the 'falling underground with charge' issues --- src/server/game/Movement/PathGenerator.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/server') diff --git a/src/server/game/Movement/PathGenerator.cpp b/src/server/game/Movement/PathGenerator.cpp index 3140fc23296..f2e1bb518d4 100644 --- a/src/server/game/Movement/PathGenerator.cpp +++ b/src/server/game/Movement/PathGenerator.cpp @@ -477,11 +477,29 @@ void PathGenerator::BuildPointPath(const float *startPoint, const float *endPoin dtStatus dtResult = DT_FAILURE; if (_straightLine) { - // if the path is a straight line then start and end position are enough dtResult = DT_SUCCESS; - pointCount = 2; - memcpy(&pathPoints[0], startPoint, sizeof(float)* 3); - memcpy(&pathPoints[3], endPoint, sizeof(float)* 3); + pointCount = 1; + memcpy(&pathPoints[VERTEX_SIZE * 0], startPoint, sizeof(float)* 3); // first point + + // path has to be split into polygons with dist SMOOTH_PATH_STEP_SIZE between them + G3D::Vector3 startVec = G3D::Vector3(startPoint[0], startPoint[1], startPoint[2]); + G3D::Vector3 endVec = G3D::Vector3(endPoint[0], endPoint[1], endPoint[2]); + G3D::Vector3 diffVec = (endVec - startVec); + G3D::Vector3 prevVec = startVec; + float len = diffVec.length(); + diffVec *= SMOOTH_PATH_STEP_SIZE / len; + while (len > SMOOTH_PATH_STEP_SIZE) + { + len -= SMOOTH_PATH_STEP_SIZE; + prevVec += diffVec; + pathPoints[VERTEX_SIZE * pointCount + 0] = prevVec.x; + pathPoints[VERTEX_SIZE * pointCount + 1] = prevVec.y; + pathPoints[VERTEX_SIZE * pointCount + 2] = prevVec.z; + ++pointCount; + } + + memcpy(&pathPoints[VERTEX_SIZE * pointCount], endPoint, sizeof(float)* 3); // last point + ++pointCount; } else if (_useStraightPath) { -- cgit v1.2.3