fix: update move fly and swim.

This commit is contained in:
Tungdv
2025-12-06 18:49:21 +07:00
parent 09322bcf41
commit 4c863a8ee8
+75 -1
View File
@@ -11,6 +11,7 @@ namespace BrewMonster.Scripts
// Cho phép CECHostMove gán mask theo scene (giữ linh hoạt nhưng không phá cấu trúc)
public static LayerMask BrushMask { get; set; } = 1<<7;
public static LayerMask TerrainMask { get; set; } = 1<<6;
public static LayerMask WaterMask { get; set; } = 1<<8;
const float LOCAL_EPSILON = 1e-5f;
@@ -22,7 +23,7 @@ namespace BrewMonster.Scripts
CDR_WATER = 0x4;
}
static LayerMask UsedMask_Ground() => BrushMask | TerrainMask;
static LayerMask UsedMask_Ground() => BrushMask | TerrainMask | WaterMask;
static bool CollideWithEnv(env_trace_t pEnvTrc)
{
@@ -569,7 +570,80 @@ namespace BrewMonster.Scripts
static void AirMove(ref ON_AIR_CDR_INFO awmInfo)
{
float DIST_EPSILON = 1e-4f;
int MAX_TRY = 1;
float VEL_REFLECT = 0.0f;
float fTime = awmInfo.t;
//@todo : is it necessary to clamp the speed? By Kuiwu[20/9/2005]
float fSpeed = awmInfo.fSpeed;
if (fSpeed * fTime < DIST_EPSILON)
{
//@todo : set the output param. By Kuiwu[20/9/2005]
return;
}
A3DVECTOR3 vStart = new A3DVECTOR3(awmInfo.vCenter);
A3DVECTOR3 vExt = new A3DVECTOR3(awmInfo.vExtent);
A3DVECTOR3 vVelDir = new A3DVECTOR3(awmInfo.vVelDir);
float dtp = 0f;
A3DVECTOR3 vVelocity = new A3DVECTOR3(vVelDir* fSpeed);
if ((dtp = A3DVECTOR3.DotProduct(vVelDir, awmInfo.vTPNormal)) < 0.0f)
{
//vVelocity = (vVelDir - awmInfo.vTPNormal * dtp - awmInfo.vTPNormal*dtp * 0.01f) * fSpeed;
vVelocity = (vVelDir - awmInfo.vTPNormal * dtp) * fSpeed;
}
A3DVECTOR3 vDelta = new A3DVECTOR3(vVelocity* fTime),
vNormal = new A3DVECTOR3(),
vFinalPos = new A3DVECTOR3(vStart);
int nTry = 0;
bool bClear = true;
env_trace_t trcInfo;
trcInfo.bWaterSolid = true;
trcInfo.dwCheckFlag = CDR_EVN.CDR_TERRAIN | CDR_EVN.CDR_BRUSH | CDR_EVN.CDR_WATER;
trcInfo.vExt = vExt;
RaycastHit hit;
while (nTry < MAX_TRY)
{
if (vDelta.SquaredMagnitude() < DIST_EPSILON)
{
break;
}
trcInfo.vStart = vStart;
trcInfo.vDelta = vDelta;
trcInfo.vTerStart = vStart;
trcInfo.vTerStart.y -= vExt.y;
trcInfo.vWatStart = vStart;
trcInfo.vWatStart.y -= vExt.y;
//bClear = !CollideWithEnv(&trcInfo);
bClear = !Physics.Raycast(EC_Utility.ToVector3(vStart),
EC_Utility.ToVector3(vStart + vVelDir).normalized,
out hit,
EC_Utility.ToVector3(vDelta).magnitude,
UsedMask_Ground());
++nTry;
if (bClear)
{
vFinalPos = vStart + vDelta;
}
else
{
vFinalPos = EC_Utility.ToA3DVECTOR3(hit.point);
vNormal = EC_Utility.ToA3DVECTOR3(hit.normal);
}
//vStart += vDelta * trcInfo.fFraction;
//vFinalPos = vStart;
//fTime -= fTime * trcInfo.fFraction;
//vNormal = trcInfo.vHitNormal;
//fSpeed = A3DVECTOR3.Normalize(vVelocity,out vVelDir);
//fSpeed *= (1 - nTry * 0.1f);
//dtp = A3DVECTOR3.DotProduct(vNormal, vVelDir);
//vVelocity = (vVelDir - vNormal * dtp - vNormal * dtp * VEL_REFLECT) * fSpeed;
//vDelta = vVelocity * fTime;
}
}
static void WaterMove(ref ON_AIR_CDR_INFO awmInfo)