fix: update code logic jump (error in line 392 check normal)

This commit is contained in:
Tungdv
2025-12-24 19:34:44 +07:00
parent b7ab7bc8c4
commit f03425d5d8
+10 -34
View File
@@ -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;