From f03425d5d8ab20a240c2b6f0a8a2ce8223a91cd7 Mon Sep 17 00:00:00 2001 From: Tungdv Date: Wed, 24 Dec 2025 19:34:44 +0700 Subject: [PATCH 1/2] fix: update code logic jump (error in line 392 check normal) --- Assets/PerfectWorld/Scripts/Move/EC_CDR.cs | 44 +++++----------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/Move/EC_CDR.cs b/Assets/PerfectWorld/Scripts/Move/EC_CDR.cs index da7d148a43..453e771ba5 100644 --- a/Assets/PerfectWorld/Scripts/Move/EC_CDR.cs +++ b/Assets/PerfectWorld/Scripts/Move/EC_CDR.cs @@ -200,6 +200,7 @@ namespace BrewMonster CDRInfo.fMoveDist = 0.0f; bool bFreeFall = (CDRInfo.vTPNormal.y < CDRInfo.fSlopeThresh); + Debug.LogError("CDRInfo.vTPNormal.y = " + CDRInfo.vTPNormal.y); if (CDRInfo.fYVel < VEL_EPSILON && CDRInfo.fYVel > -VEL_EPSILON && CDRInfo.fSpeed < VEL_EPSILON && CDRInfo.fSpeed > -VEL_EPSILON && !bFreeFall) return; @@ -207,11 +208,12 @@ namespace BrewMonster bool bJump = (fYVel > 0.5f); Vector3 vVelocity = CDRInfo.fSpeed * EC_Utility.ToVector3(CDRInfo.vXOZVelDir) + fYVel * Vector3.up; - + Debug.LogError("1 vVelocity = " + vVelocity); if (bFreeFall) { - vVelocity += -CDRInfo.fGravityAccel * CDRInfo.t * Vector3.up; + vVelocity += -CDRInfo.fGravityAccel * CDRInfo.t * Vector3.up; + Debug.LogError("2 vVelocity = " + vVelocity); fYVel += -CDRInfo.fGravityAccel * CDRInfo.t; } A3DVECTOR3 vVelDir = EC_Utility.ToA3DVECTOR3(vVelocity); @@ -225,11 +227,12 @@ namespace BrewMonster } } vVelocity = EC_Utility.ToVector3(vVelDir) * fVelSpeed; - + Debug.LogError("3 vVelocity = " + vVelocity); float dtp = DotProduct(vVelDir, CDRInfo.vTPNormal); if (dtp < 0f || !bJump) { vVelocity = EC_Utility.ToVector3((vVelDir -(CDRInfo.vTPNormal) * dtp - (CDRInfo.vTPNormal) * dtp * 0.01f) * fVelSpeed); + Debug.LogError("4 vVelocity = " + vVelocity); } CDRInfo.vAbsVelocity = EC_Utility.ToA3DVECTOR3(vVelocity); @@ -253,11 +256,11 @@ namespace BrewMonster { vDelta = vVelocity * (fTime); float fDeltaDist = vDelta.magnitude; - //Debug.LogError("fDeltaDist = " + fDeltaDist + " vVelocity = " + vVelocity + " fTime = " + fTime + " speed = " + (fDeltaDist / fTime)); + Vector3 posFoot = vStart - Vector3.up * vExt.y; + Debug.LogError("fDeltaDist = " + fDeltaDist + " vVelocity = " + vVelocity + " fTime = " + fTime + " speed = " + (fDeltaDist / fTime) + " posFoot + vDelta = " + (posFoot + vDelta) + " posFoot = " + posFoot); vFinalPos = vStart; if (fDeltaDist < DIST_EPSILON) break; - Vector3 posFoot = vStart - Vector3.up * vExt.y; if (Physics.Raycast(vStart, (Vector3.down).normalized, out RaycastHit hit, vExt.y, mask)) { if (hit.point.y > posFoot.y) @@ -267,35 +270,7 @@ namespace BrewMonster } bool bClear = !Physics.Raycast(posFoot, (posFoot + vDelta).normalized, out hit, fDeltaDist, mask); - //bool bClear = false;//!Physics.Raycast(posFoot, (posFoot + vDelta).normalized, out hit, fDeltaDist, mask); - //Debug.DrawRay(posFoot, vDelta, Color.yellow, 1f); - //float fFraction = 100f; - //if(fDeltaDist < 1E-5f) - //{ - // fFraction = 0f; - //} - //else - //{ - // if (Physics.Raycast(posFoot, (posFoot + vDelta).normalized, out hit, fDeltaDist, mask)) - // { - // if (Vector3.Dot(hit.normal, vDelta) <= 0.01f) - // { - // float t = Vector3.Distance(hit.point, posFoot); - // float tempfFraction = (t - 5E-4f) / fDeltaDist; - // if (tempfFraction < fFraction && t >= 0.0f && t <= fDeltaDist) - // { - // fFraction = tempfFraction; - // if (tempfFraction < 0f) - // { - // fFraction = 0f; - // } - // } - // } - // } - //} - ////Debug.LogError("fFraction = " + fFraction); - //bClear = !(fFraction < 1.0f + 1E-4f); - + Debug.DrawLine(posFoot, posFoot + vDelta, Color.yellow, 10f); nTry++; if (bClear) { @@ -406,6 +381,7 @@ namespace BrewMonster // “vertical ground trace” – thay RetrieveSupportPlane Vector3 vTPNormal = Vector3.zero; Vector3 vFinal = vFinalPos; + mask = BrushMask; float downDist = 0.3f; if (bPull) downDist = CDRInfo.fStepHeight + 0.1f; From b76622942599e09a8571972c40d3005c5d79ad88 Mon Sep 17 00:00:00 2001 From: Tungdv Date: Thu, 25 Dec 2025 18:13:21 +0700 Subject: [PATCH 2/2] fix: update logic jump HP on ground. --- .../Scripts/Managers/EC_HostInputFilter.cs | 1 - Assets/PerfectWorld/Scripts/Move/EC_CDR.cs | 96 ++++++++----------- Assets/Scripts/CECHostPlayer.cs | 4 +- 3 files changed, 42 insertions(+), 59 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/Managers/EC_HostInputFilter.cs b/Assets/PerfectWorld/Scripts/Managers/EC_HostInputFilter.cs index 4daee7ebcf..b0ad231067 100644 --- a/Assets/PerfectWorld/Scripts/Managers/EC_HostInputFilter.cs +++ b/Assets/PerfectWorld/Scripts/Managers/EC_HostInputFilter.cs @@ -320,7 +320,6 @@ namespace BrewMonster m_CDRInfo.vAbsVelocity.y = fVertSpeed; m_CDRInfo.fYVel = 0.0f; m_CDRInfo.vTPNormal = EC_Utility.ToA3DVECTOR3(Vector3.zero); - if (m_iJumpCount == 1) { m_MoveCtrl.SendMoveCmd(GetPos(), 2, GPDataTypeHelper.g_vAxisY, (m_CDRInfo.vAbsVelocity), m_iMoveMode, true); diff --git a/Assets/PerfectWorld/Scripts/Move/EC_CDR.cs b/Assets/PerfectWorld/Scripts/Move/EC_CDR.cs index 453e771ba5..afda5d9a8c 100644 --- a/Assets/PerfectWorld/Scripts/Move/EC_CDR.cs +++ b/Assets/PerfectWorld/Scripts/Move/EC_CDR.cs @@ -17,8 +17,16 @@ namespace BrewMonster public static LayerMask TerrainMask { get; set; } = 1 << 6; public static LayerMask WaterMask { get; set; } = 1 << 8; + public static RaycastHit[] hits = new RaycastHit[5]; + const float LOCAL_EPSILON = 1e-5f; - const float FLY_MAX_HEIGHT = 800.0f; // ·ÉÐеÄ×î´ó¸ß¶È£¡ + const float FLY_MAX_HEIGHT = 800.0f; // ·ÉÐеÄ×î´ó¸ß¶È£¡ + + const float VEL_EPSILON = 1e-4f; + const float DIST_EPSILON = 1e-4f; + const float NORMAL_EPSILON = 1e-2f; + const float VEL_MAX_SPEED = 200f; + const float VEL_REFLECT = 0.3f; // change this array when some new submap can go! static uint[,] available_maps = @@ -177,30 +185,24 @@ namespace BrewMonster float dist = fDeltaY + vExt.y;//Mathf.Max(fDeltaY, 0f) + vExt.y; Vector3 origin = vStart /*+ Vector3.down * vExt.y*/; - if (Physics.Raycast(origin, Vector3.down, out RaycastHit hit, dist, mask)) + int countHits = Physics.RaycastNonAlloc(origin, Vector3.down, hits, dist, mask); + if (countHits > 0) { - vHitNormal = hit.normal; - //Debug.DrawLine(origin, vHitNormal, Color.black, 10f); - vEnd = new Vector3(vStart.x, hit.point.y + vExt.y, vStart.z); + vHitNormal = hits[0].normal; + vEnd = new Vector3(vStart.x, hits[0].point.y + vExt.y, vStart.z); bSupport = (vHitNormal.y >= 0f); return true; } - return true; // không thấy ground → bSupport=false + return true; } // ======= STATIC OnGroundMove – GIỮ NGUYÊN VAI TRÒ TOÀN CỤC (C API) ======= public static void OnGroundMove(ref CDR_INFO CDRInfo) { - const float VEL_EPSILON = 1e-4f; - const float DIST_EPSILON = 1e-4f; - const float NORMAL_EPSILON = 1e-2f; - const float VEL_MAX_SPEED = 200f; - const float VEL_REFLECT = 0.3f; CDRInfo.fMoveDist = 0.0f; bool bFreeFall = (CDRInfo.vTPNormal.y < CDRInfo.fSlopeThresh); - Debug.LogError("CDRInfo.vTPNormal.y = " + CDRInfo.vTPNormal.y); if (CDRInfo.fYVel < VEL_EPSILON && CDRInfo.fYVel > -VEL_EPSILON && CDRInfo.fSpeed < VEL_EPSILON && CDRInfo.fSpeed > -VEL_EPSILON && !bFreeFall) return; @@ -208,31 +210,26 @@ namespace BrewMonster bool bJump = (fYVel > 0.5f); Vector3 vVelocity = CDRInfo.fSpeed * EC_Utility.ToVector3(CDRInfo.vXOZVelDir) + fYVel * Vector3.up; - Debug.LogError("1 vVelocity = " + vVelocity); if (bFreeFall) { vVelocity += -CDRInfo.fGravityAccel * CDRInfo.t * Vector3.up; - Debug.LogError("2 vVelocity = " + vVelocity); fYVel += -CDRInfo.fGravityAccel * CDRInfo.t; } A3DVECTOR3 vVelDir = EC_Utility.ToA3DVECTOR3(vVelocity); float fVelSpeed = vVelDir.Normalize(); if (!bFreeFall) { - //fVelSpeed = Mathf.Max(fVelSpeed, VEL_MAX_SPEED); if (fVelSpeed > VEL_MAX_SPEED) { fVelSpeed = VEL_MAX_SPEED; } } vVelocity = EC_Utility.ToVector3(vVelDir) * fVelSpeed; - Debug.LogError("3 vVelocity = " + vVelocity); float dtp = DotProduct(vVelDir, CDRInfo.vTPNormal); if (dtp < 0f || !bJump) { vVelocity = EC_Utility.ToVector3((vVelDir -(CDRInfo.vTPNormal) * dtp - (CDRInfo.vTPNormal) * dtp * 0.01f) * fVelSpeed); - Debug.LogError("4 vVelocity = " + vVelocity); } CDRInfo.vAbsVelocity = EC_Utility.ToA3DVECTOR3(vVelocity); @@ -252,42 +249,39 @@ namespace BrewMonster trcInfo.dwCheckFlag = CDR_EVN.CDR_TERRAIN | CDR_EVN.CDR_BRUSH; trcInfo.vExt = CDRInfo.vExtent; + int countHits = 0; while (nTry < 1) { vDelta = vVelocity * (fTime); float fDeltaDist = vDelta.magnitude; Vector3 posFoot = vStart - Vector3.up * vExt.y; - Debug.LogError("fDeltaDist = " + fDeltaDist + " vVelocity = " + vVelocity + " fTime = " + fTime + " speed = " + (fDeltaDist / fTime) + " posFoot + vDelta = " + (posFoot + vDelta) + " posFoot = " + posFoot); vFinalPos = vStart; if (fDeltaDist < DIST_EPSILON) break; - - if (Physics.Raycast(vStart, (Vector3.down).normalized, out RaycastHit hit, vExt.y, mask)) + countHits = Physics.RaycastNonAlloc(vStart, (Vector3.down * vExt.y).normalized, hits, vExt.y, mask); + if (countHits > 0) { - if (hit.point.y > posFoot.y) + if (hits[0].point.y >= posFoot.y) { - posFoot.y = hit.point.y; + posFoot.y = hits[0].point.y; } } - - bool bClear = !Physics.Raycast(posFoot, (posFoot + vDelta).normalized, out hit, fDeltaDist, mask); - Debug.DrawLine(posFoot, posFoot + vDelta, Color.yellow, 10f); + //Debug.LogError("fDeltaDist = " + fDeltaDist + " vVelocity = " + vVelocity + " fTime = " + fTime + " speed = " + (fDeltaDist / fTime) + " posFoot + vDelta = " + (posFoot + vDelta) + " posFoot = " + posFoot); + countHits = Physics.RaycastNonAlloc(posFoot, (posFoot + vDelta).normalized, hits, fDeltaDist, mask); + bool bClear = !(countHits > 0); nTry++; - if (bClear) + if (bClear || (countHits > 0 && Vector3.Distance(hits[0].point, posFoot) < 0.0009f)) // Is 0.0009f the tolerance used to check if two points are the same? { - //Debug.LogError("bClear = true"); - //Debug.DrawLine(posFoot, posFoot + vDelta, Color.yellow, 10f); vFinalPos = vStart + vDelta; CDRInfo.fMoveDist += fDeltaDist; break; } - //Debug.LogError("bClear = false"); - vStart = hit.point + Vector3.up * vExt.y; - //vStart += vDelta * trcInfo.fFraction + Vector3.up * vExt.y; + vStart = hits[0].point + Vector3.up * vExt.y; vFinalPos = vStart; - if (Physics.Raycast(vStart, (Vector3.down).normalized, out hit, vExt.y, mask)) + countHits = Physics.RaycastNonAlloc(vStart, (Vector3.down).normalized, hits, vExt.y, mask); + if (countHits > 0) { - vNormal = hit.normal; + vNormal = hits[0].normal; } else { @@ -297,45 +291,36 @@ namespace BrewMonster // Step-up (giữ tinh thần bản gốc) if (!bFreeFall && !bTryPull && !bJump) { - //float skin = 0.01f; - posFoot = vStart - Vector3.up * vExt.y /*+ Vector3.up * CDRInfo.fStepHeight*/; - if (Physics.Raycast(vStart, (vStart + Vector3.down).normalized, out hit, vExt.y, mask)) + posFoot = vStart - Vector3.up * vExt.y; + countHits = Physics.RaycastNonAlloc(vStart, (vStart + Vector3.down).normalized, hits, vExt.y, mask); + if (countHits > 0) { - if (hit.point.y > posFoot.y) + if (hits[0].point.y > posFoot.y) { - posFoot.y = hit.point.y; + posFoot.y = hits[0].point.y; } } - //Vector3 vStartUp = new Vector3(0f, CDRInfo.fStepHeight, 0f); - bPull = !Physics.Raycast(posFoot, (Vector3.up).normalized, out hit, CDRInfo.fStepHeight, mask); - //if(bPull == false) - //{ - // Debug.LogError("bPull = false hit = " + hit.collider.name); - //} + countHits = Physics.RaycastNonAlloc(posFoot, (Vector3.up).normalized, hits, CDRInfo.fStepHeight, mask); + bPull = !(countHits > 0); if (bPull) { vStart += Vector3.up * CDRInfo.fStepHeight; posFoot = vStart - Vector3.up * vExt.y; fDeltaDist = (vVelocity.normalized).magnitude; - bool bMove = !Physics.Raycast(posFoot, (posFoot + vVelocity).normalized, out hit, fDeltaDist, mask); - //Vector3 posDelta = vDelta; + countHits = Physics.RaycastNonAlloc(posFoot, (posFoot + vVelocity).normalized, hits, fDeltaDist, mask); + bool bMove = !(countHits > 0); if (!bMove) { - //posDelta = vFinalPos - (hit.point + Vector3.up * vExt.y); - fDeltaDist *= Vector3.Distance(vFinalPos, (hit.point + Vector3.up * vExt.y)) / fDeltaDist; - vFinalPos = hit.point + Vector3.up * vExt.y; - //vFinalPos = vStart + vDelta * tmpInfo.fFraction + Vector3.up * vExt.y; + fDeltaDist *= Vector3.Distance(vFinalPos, (hits[0].point + Vector3.up * vExt.y)) / fDeltaDist; + vFinalPos = hits[0].point + Vector3.up * vExt.y; } else { - //Debug.DrawLine(vFinalPos, vFinalPos + vDelta, Color.red, 10f); vFinalPos += vDelta; } - //Debug.LogError("vExt.x * vExt.x * 4 = " + vExt.x * vExt.x * 4 + " fDeltaDist = " + fDeltaDist); if (fDeltaDist < (vExt.x * vExt.x * 4)) { - //Debug.LogError("set bPull = false"); vFinalPos.y -= CDRInfo.fStepHeight; bPull = false; } @@ -363,7 +348,6 @@ namespace BrewMonster { if (vNormal.y >= CDRInfo.fSlopeThresh || vNormal.y < -NORMAL_EPSILON) { - //Debug.LogError("1 fYVel = 0f"); fYVel = 0f; } } @@ -371,7 +355,6 @@ namespace BrewMonster { if (vNormal.y >= CDRInfo.fSlopeThresh) { - //Debug.LogError("2 fYVel = 0f"); fYVel = 0f; } } @@ -381,7 +364,7 @@ namespace BrewMonster // “vertical ground trace” – thay RetrieveSupportPlane Vector3 vTPNormal = Vector3.zero; Vector3 vFinal = vFinalPos; - mask = BrushMask; + //mask = BrushMask; float downDist = 0.3f; if (bPull) downDist = CDRInfo.fStepHeight + 0.1f; @@ -408,7 +391,6 @@ namespace BrewMonster if ((vTPNormal.y >= CDRInfo.fSlopeThresh && fYVel < 0.0f) || (!bJump && fYVel > 0.0f)) { - //Debug.LogError("3 fYVel = 0f"); fYVel = 0.0f; } diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index 6106393057..e4229fd7d5 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -2253,7 +2253,9 @@ namespace BrewMonster m_MoveCtrl.SetLastSevPos(EC_Utility.ToA3DVECTOR3(pos)); //m_CDRInfo.vTPNormal = GroundCheck(out RaycastHit hit) ? hit.normal : Vector3.zero; m_CDRInfo.vExtent = m_aabbServer.Extents; - if (Physics.Raycast(pos, Vector3.down, out RaycastHit hit, 0.1f, 1<<6)) + Vector3 pStart = pos; + pos.y += m_CDRInfo.vExtent.y; + if (Physics.Raycast(pos, Vector3.down, out RaycastHit hit, m_CDRInfo.vExtent.y, 1<<6)) { m_CDRInfo.vTPNormal = EC_Utility.ToA3DVECTOR3(hit.normal); }