//@ Process //@ 1.landing position 2.set target dir to object public bool SetPositionLandDirectly(CNaviMesh meshNavi) { Vector3 v3DirDown = Vector3.down; Vector3 v3PosCurrent; Vector3 v3PosVertical; bool bIntersectedWithLanding = false; float fAdjust = dist_adjustpos_up; v3PosCurrent = positionUnit; v3PosVertical = v3PosCurrent + (Vector3.up * fAdjust); Ray rayObj = new Ray(v3PosVertical, v3DirDown); int iTriLandingCurr = -1; RaycastHit raycastHit_info = new RaycastHit(); bool bCrossoverAdjustedWayto = false; bIntersectedWithLanding = meshNavi.GetComponent<Collider>().Raycast(rayObj, out raycastHit_info, dist_raycast_adjust); if (false == bIntersectedWithLanding) { //Debug.Log("ERROR. SetPositionLandDirectly()//not Landing."); return false; } iTriLandingCurr = raycastHit_info.triangleIndex; setLandingTri(iTriLandingCurr); positionUnit = raycastHit_info.point; { Vector3 v3PosIntersected = raycastHit_info.point; Vector2[] arrv2PntOBJBoundary = boundaryUnit2D(); if (true == _bMoveShortestSight) { bCrossoverAdjustedWayto = meshNavi.navigation.getPosWayTo_Portal(iTriLandingCurr, arrv2PntOBJBoundary, ref m_pntWayTo); } else { CNAVICELL.E_CELL_STATUS ecellStatus = meshNavi.navigation.getPosCurrentWayToGoal(iTriLandingCurr, ref m_pntWayTo); switch (ecellStatus) { case CNAVICELL.E_CELL_STATUS.CELL_STATUS_GOAL: { bCrossoverAdjustedWayto = true; reachtheGoal = true; } break; case CNAVICELL.E_CELL_STATUS.CELL_STATUS_BLOCK: case CNAVICELL.E_CELL_STATUS.CELL_STATUS_ROAD: { bCrossoverAdjustedWayto = true; } break; case CNAVICELL.E_CELL_STATUS.CELL_STATUS_NULL: default: { bCrossoverAdjustedWayto = false; } break; } // switch (ecellStatus) } // if (true == _bMoveShortestSight) if (false == bCrossoverAdjustedWayto || (int)CNAVICELL.E_CELL_STATUS.CELL_STATUS_NULL == m_pntWayTo._idxnavicell) { Debug.Log("Error(critical) set Unit landing.=" + (CNAVICELL.E_CELL_STATUS)m_pntWayTo._idxnavicell + "//" + UnityEngine.Random.Range(0.0f, 1000.0f)); return false; } //@ Set dir standard forwardforMovement = m_pntWayTo._dirEntrytoNext; forwardforAngle = m_pntWayTo._dirEntrytoNext; positionUnit = v3PosIntersected; } // if (false == meshNavi.getCell(iTriLandingCurr).IsBlockCell()) //@ To slicely adjustment position for rigidbody height. //if (rigidbody) //{ // Vector3 v3PositionAdjust = new Vector3(); // v3PositionAdjust = positionUnit; // v3PositionAdjust.y = v3PositionAdjust.y + CMATH.FEPSILON_F3; // positionUnit = v3PositionAdjust; // setPosHeadObj(v3PositionAdjust, Vector3.zero); //} return bCrossoverAdjustedWayto; } // public bool SetPositionLandDirectly()
} // void Update_Collision_sameforce() #endregion // collisionupdateprocess //@ Update movement process bool Update_unitWalking_Movement(float fTimeDelta, CNaviMesh meshNavi) { if (true == _bRequestLandDirectly) { SetPositionLandDirectly(meshNavi); _bRequestLandDirectly = false; } //@1.Forced setting, Cell wasn't prepared go to way to goal. if (false == _bProcessWalking_Static) { return true; } //@2.No landing mesh. if (null == meshNavi) { Debug.Log("(ERROR. null == meshNavi//Update_objDyn//"); return false; } //@3.Current landing triangle is NULL. (== No landing mesh) if (CTRI.NULL_TRI == getLandingTri()) { //Vector3 v3PosObj = positionUnit; //Debug.Log("(ERROR. NULL_TRI == getLandingTri()//Position(x=" // + v3PosObj.x + ")(y=" // + v3PosObj.y + ")(z=" // + v3PosObj.z + ")//Update_objDyn//"); return false; } //@4.Reach GOAL if (true == reachtheGoal) { return true; } Vector3 v3PosCurrent = positionUnit; Vector3 v3PosCurrAdjusted = v3PosCurrent; Vector3 v3PosNextAdjusted = v3PosCurrent + (m_pntWayTo._dirEntrytoNext * fTimeDelta * speedmove); bool bCrossoverAdjustedWayto = false; //@ crossover == true than adjustment positioning. { int iCountofLevel = m_pntWayTo._ileveltoGoal; Vector3 v3PosIntersected = new Vector3(); CNavigation.CCellWayto pntWayTo_ = new CNavigation.CCellWayto(m_pntWayTo); CNAVICELL.E_CELL_STATUS ecellStatus = CNAVICELL.E_CELL_STATUS.CELL_STATUS_NULL; //@ penetrate n-cell. for (int iterlevel = 0; iterlevel <= iCountofLevel; ++iterlevel) { if (true == pntWayTo_.crossoverTest(v3PosCurrAdjusted, v3PosNextAdjusted)) { setLandingTri(pntWayTo_._idxnavicell); if (true == pntWayTo_.IntersectedPosToEdge(v3PosCurrAdjusted, v3PosNextAdjusted, ref v3PosIntersected)) { ecellStatus = meshNavi.navigation.getPosNextWayTo(pntWayTo_._idxnavicell, ref pntWayTo_); if (CNAVICELL.E_CELL_STATUS.CELL_STATUS_GOAL == ecellStatus) { v3PosNextAdjusted = v3PosIntersected; } float fRemainder = (v3PosNextAdjusted - v3PosIntersected).magnitude; v3PosNextAdjusted = v3PosIntersected + (pntWayTo_._dirEntrytoNext * fRemainder); v3PosCurrAdjusted = v3PosIntersected; bCrossoverAdjustedWayto = true; } else { ecellStatus = meshNavi.navigation.getPosNextWayTo(pntWayTo_._idxnavicell, ref pntWayTo_); } } else { break; } } // for (int iterlevel = 0; iterlevel <= iCountofLevel; ++iterlevel) if (true == bCrossoverAdjustedWayto) { m_wayHorizon.renewRatioPerpend(pntWayTo_._dirEntrytoNext, pntWayTo_._posEdgeFrom0, pntWayTo_._posEdgeFrom1, pntWayTo_._ratioPerpen); m_pntWayTo = pntWayTo_; } switch (ecellStatus) { case CNAVICELL.E_CELL_STATUS.CELL_STATUS_GOAL: { reachtheGoal = true; bCrossoverAdjustedWayto = true; } break; case CNAVICELL.E_CELL_STATUS.CELL_STATUS_BLOCK: case CNAVICELL.E_CELL_STATUS.CELL_STATUS_ROAD: { bCrossoverAdjustedWayto = true; } break; } } //@ 목표각도 설정. if (true == bCrossoverAdjustedWayto) { Vector3 v3DirAngleTarget = m_pntWayTo._dirEntrytoNext; if (true == m_bVerticalInclination) { forwardforAngleTarget = new Vector3(v3DirAngleTarget.x, 0.0f, v3DirAngleTarget.z); } else { forwardforAngleTarget = v3DirAngleTarget; } forwardforMovement = m_pntWayTo._dirEntrytoNext; Vector3 v3PosRatioAdjusted = new Vector3(); m_wayHorizon.processPosPerpend(fTimeDelta, m_fratiohorizonRoad, v3PosNextAdjusted, ref v3PosRatioAdjusted); positionUnit = v3PosRatioAdjusted; } else { //@ position adjusted position, calculaed ratio on way perpendicular Vector3 v3PosRatioAdjusted = new Vector3(); m_wayHorizon.processPosPerpend(fTimeDelta, m_fratiohorizonRoad, v3PosCurrent, ref v3PosRatioAdjusted); positionUnit = v3PosRatioAdjusted; base.Update_unitDyn(fTimeDelta); } #region inclination_teritory //bool bWayInclination = false; //if(false == CMATH.similarEst_float(m_pntWayTo._dirEntrytoNext.y, 0.0f, CMATH.FEPSILON_F2)) //{ // bWayInclination = true; //} #endregion return true; } // public void Update_objWalk(float fTimeDelta)