public void OnRenderObject() { NavDebug.Draw(mHelper.mesh, mPolyRefs.buffer, mResultCount); if (mHasPosition) { DebugDraw.Circle(mPosition.point, mSearchRadius, QEUtil.SelectColor); } if (mResultCount > 0) { for (int i = 0; i < mResultCount; i++) { if (mParentRefs[i] == 0) { continue; } Vector3 center = GetBufferedCentroid(mPolyRefs.buffer[i]); Vector3 pcenter; if (mParentRefs[i] == mPosition.polyRef) { pcenter = mPosition.point; } else { pcenter = GetBufferedCentroid(mParentRefs[i]); } DebugDraw.Arrow(pcenter, center, 0, QEUtil.HeadScaleSm, NavDebug.goalColor); } } }
void OnRenderObject() { if (m_RotationDisc) { var color = ColorUtil.Chocolate; var trans = m_Manager.Body.MotionRoot; var dist = 0.5f; var pos = trans.position + Vector3.up * 0.005f; DebugDraw.Circle(pos, dist, color); DebugDraw.Arrow(pos, pos + trans.forward * dist, 0, 0.1f, color); } }
/// <summary> /// Draws the basic agent debug information. /// </summary> /// <remarks> /// <para> /// This does not include the duplicate agent information such as target and corner /// positions. /// </para> /// </remarks> /// <param name="agent">The agent to draw.</param> public void DrawBase(CrowdAgent agent) { Vector3 pos = agent.Position; CrowdAgentParams config = agent.GetConfig(); DebugDraw.Circle(pos, config.radius, neighborColor); DebugDraw.Arrow(pos + Vector3.up * config.height , pos + agent.DesiredVelocity + Vector3.up * config.height , 0, 0.05f, desiredVelocityColor); DebugDraw.Arrow(pos + Vector3.up * config.height , pos + agent.Velocity + Vector3.up * config.height , 0, 0.05f, velocityColor); }
public void OnRenderObject() { NavDebug.Draw(mHelper.mesh, false); if (mHasPosition) { DebugDraw.Circle(mPosition.point, mSearchRadius, QEUtil.SelectColor); } if (mHasWallHit) { DebugDraw.DiamondMarker(mWallHitPoint, QEUtil.MarkerScaleSm, Color.green); Vector3 normal = (mWallHitPoint + mWallNormal); DebugDraw.Arrow(mWallHitPoint, normal, 0, QEUtil.HeadScaleSm, NavDebug.goalColor); } }
/// <summary> /// Draws agent neighbor information. /// </summary> /// <param name="agent">The agent to draw.</param> public void DrawNeighbors(CrowdAgent agent) { int neighborCount = agent.NeighborCount; if (neighborCount == 0) { return; } agent.GetNeighbors(neighbors); for (int i = 0; i < neighborCount; i++) { CrowdAgent n = agent.GetNeighbor(neighbors[i]); if (n == null) { // Not sure why this happens. Bug in CrowdAgent? continue; } DebugDraw.Arrow(agent.Position, n.Position, 0, 0.05f, neighborColor); DebugDraw.Circle(n.Position, agent.GetConfig().radius, neighborColor); } }
void OnRenderObject() { if (Time.timeScale == 0 || mGroup.mesh == null) { return; } mCorridor.GetData(mCorridorData); NavDebug.Draw(mGroup.mesh, false); NavDebug.Draw(mGroup.mesh, mCorridorData); NavDebug.Draw(mCorridor.Corners); Color c = NavDebug.positionColor; c.a = 0.25f; if (mPathStart.polyRef != 0) { DebugDraw.DiamondMarker(mPathStart.point, 0.1f, c); } c = NavDebug.goalColor; c.a = 0.25f; if (mPathEnd.polyRef != 0) { DebugDraw.DiamondMarker(mPathEnd.point, 0.1f, c); } if (mOptimizeTimer > 0) { c = NavDebug.goalColor; c.a = mOptimizeTimer / TimerLength; DebugDraw.Arrow(mOptimizeStart, mOptimizeEnd, 0, 0.1f, c); DebugDraw.Circle(mOptimizeStart, optimizationRange, c); } }
/// <summary> /// Draws a debug visualization of a corridor. /// </summary> /// <param name="mesh">The navigation mesh associated with the corridor.</param> /// <param name="corridor">The corridor to draw.</param> public static void Draw(Navmesh mesh, PathCorridorData corridor) { if (corridor.pathCount == 0) { return; } DebugDraw.SimpleMaterial.SetPass(0); Vector3[] tileVerts = null; for (int iPoly = 0; iPoly < corridor.pathCount; iPoly++) { NavmeshTile tile; NavmeshPoly poly; mesh.GetTileAndPoly(corridor.path[iPoly], out tile, out poly); if (poly.Type == NavmeshPolyType.OffMeshConnection) { continue; } NavmeshTileHeader header = tile.GetHeader(); if (tileVerts == null || tileVerts.Length < 3 * header.vertCount) { // Resize. tileVerts = new Vector3[header.vertCount]; } tile.GetVerts(tileVerts); GL.Begin(GL.TRIANGLES); GL.Color(polygonOverlayColor); int pA = poly.indices[0]; for (int i = 2; i < poly.vertCount; i++) { int pB = poly.indices[i - 1]; int pC = poly.indices[i]; GL.Vertex(tileVerts[pA]); GL.Vertex(tileVerts[pB]); GL.Vertex(tileVerts[pC]); } GL.End(); // Not drawing boundaries since it would obscure other agent // debug data. } Vector3 v = corridor.position; DebugDraw.XMarker(v, positionScale, positionColor); DebugDraw.Circle(v, positionScale, positionColor); DebugDraw.Circle(v, positionScale * 0.5f, positionColor); DebugDraw.Circle(v, positionScale * 0.25f, positionColor); v = corridor.target; DebugDraw.XMarker(v, goalScale, goalColor); DebugDraw.Circle(v, goalScale, goalColor); DebugDraw.Circle(v, goalScale * 0.5f, goalColor); DebugDraw.Circle(v, goalScale * 0.25f, goalColor); }
private Vector3 GetAverageRaycast(float offsetX, float offsetZ, int rayCount = 2) { int maxRays = 4; offsetX *= 2; offsetZ *= 2; rayCount = Mathf.Clamp(rayCount, 2, maxRays); int totalRays = rayCount * rayCount + 1; Vector3[] combinedCast = new Vector3[totalRays]; int average = 0; Vector3 rayOrigin = m_Transform.TransformPoint(0 - offsetX * 0.5f, m_MaxStepHeight + m_SkinWidth, 0 - offsetZ * 0.5f); float rayLength = m_MaxStepHeight * 2; float xSpacing = offsetX / (rayCount - 1); float zSpacing = offsetZ / (rayCount - 1); bool raycastHit = false; Vector3 hitPoint = Vector3.zero; Vector3 raycast = m_Transform.TransformPoint(0, m_MaxStepHeight, 0); if (m_DebugCollisions) { Debug.DrawRay(raycast, RelativeInputVector.normalized, Color.blue); } RaycastHit hit; int index = 0; for (int z = 0; z < rayCount; z++) { for (int x = 0; x < rayCount; x++) { raycastHit = false; hitPoint = Vector3.zero; raycast = rayOrigin + (m_Transform.forward * zSpacing * z) + (m_Transform.right * xSpacing * x); //raycast += RelativeInputVector.normalized * Time.deltaTime; if (Physics.Raycast(raycast, Vector3.down, out hit, rayLength, m_Layers.SolidLayers)) { hitPoint = hit.point; average++; raycastHit = true; } combinedCast[index] = hitPoint; index++; if (m_DebugCollisions) { Debug.DrawRay(raycast, Vector3.down * rayLength, (raycastHit ? Color.green : Color.red)); } } } hitPoint = Vector3.zero; raycastHit = false; raycast = m_Transform.TransformPoint(0, m_MaxStepHeight, 0); //originRaycast += RelativeInputVector.normalized * Time.deltaTime; if (Physics.Raycast(raycast, Vector3.down, out hit, 0.4f, m_Layers.SolidLayers)) { hitPoint = hit.point; average++; raycastHit = true; } combinedCast[totalRays - 1] = hitPoint; if (m_DebugCollisions) { DebugDraw.Circle(raycast, Vector3.up * rayLength, 0.2f, (raycastHit ? Color.blue : Color.red)); } average = Mathf.Clamp(average, 1, int.MaxValue); Vector3 averageHitPosition = Vector3.zero; float xTotal = 0f, yTotal = 0f, zTotal = 0f; for (int i = 0; i < combinedCast.Length; i++) { xTotal += combinedCast[i].x; yTotal += combinedCast[i].y; zTotal += combinedCast[i].z; } averageHitPosition.Set(xTotal / average, yTotal / average, zTotal / average); if (m_DebugCollisions) { DebugDraw.DrawMarker(averageHitPosition, 0.2f, Color.blue); } return(averageHitPosition); }