bool intersectNavimesh(CNaviMesh navimesh, Vector3 v3PosUnit, ref Vector3 v3PosIntersected) { Vector3 v3PosSimulate = v3PosUnit; v3PosSimulate.y = v3PosSimulate.y + dist_adjustpos_up; Ray rayTestsimulate = new Ray(v3PosSimulate, Vector3.down); RaycastHit casthitted = new RaycastHit(); bool bIntersected = navimesh.GetComponent<Collider>().Raycast(rayTestsimulate, out casthitted, dist_raycast_adjust); if (true == bIntersected) { v3PosIntersected = casthitted.point; } return bIntersected; }
//@ 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()