private void setPoint(int index) { if (index >= _points.Points.Count || index < 0) { return; } _pointIndex = index; _point = _points.Points[index]; _searchPosition = _point.Position; _hasPoint = true; _hasPreviousPoint = true; _previousPointIndex = index; _hasSearchDirection = true; _searchDirection = (_point.Position - transform.position).normalized; _hasApproached = !shouldApproach(_point); if (shouldRunTo(_point.Position)) { run(); } else { walk(); } }
private int addPoint(SearchPoint point) { point.CalcVisibility(VerifyDistance, false); var index = _points.Add(point); if (!_block.Empty) { if (_block.IsClose(point, Advanced.BlockThreshold, Advanced.BlockCenterThreshold)) { _block.Add(index); return(index); } } for (int i = 0; i < _blocks.Count; i++) { if (_blocks[i].IsClose(point, Advanced.BlockThreshold, Advanced.BlockCenterThreshold)) { _blocks[i].Add(index); return(index); } } var new_ = _blockCache.Take(); new_.Add(index); _blocks.Add(new_); return(index); }
private void debugPoint(SearchPoint point, bool wasInvestigated, Color color) { Debug.DrawLine(point.Position, point.Position + Vector3.up * (wasInvestigated ? 0.2f : 0.75f), color); //if (point.Left >= 0) Debug.DrawLine(point.Position, point.Position + (_points.Points[point.Left].Position - point.Position) * 0.25f, Color.white); //if (point.Right >= 0) Debug.DrawLine(point.Position, point.Position + (_points.Points[point.Right].Position - point.Position) * 0.25f, Color.magenta); }
/// <summary> /// Told by the brains to start searching a ta position. /// </summary>> public void ToSearchAt(SearchPoint point) { startSearch(); setPoint(addPoint(point)); _hasBlockDirection = _hasSearchDirection; _blockDirection = _searchDirection; }
private bool areCloseEnough(InvestigatedPoint a, SearchPoint b) { if (Vector3.Distance(a.Position, b.Position) < 0.5f) { return(true); } return(false); }
public bool IsClose(SearchPoint point, float threshold, float middleThreshold) { if (Vector3.Distance(Center, point.Position) < threshold) { return(true); } foreach (var i in Indices) { if (Vector3.Distance(Data.Points[i].Position, point.Position) < threshold) { return(true); } } return(false); }
private bool canBeInvestigated(SearchPoint point) { var position = point.Position + Vector3.up * VerifyHeight; var distanceToPoint = Vector3.Distance(transform.position, position); var checkDistance = VerifyDistance; if (point.Visibility < checkDistance) { checkDistance = point.Visibility; } if (distanceToPoint < checkDistance && (distanceToPoint < 1 || AIUtil.IsInSight(_actor, position, checkDistance, FieldOfView))) { return(!point.RequiresReaching || distanceToPoint < 1.1f); } return(false); }
private static void possiblyAddRightPoint(ref int index, SearchPoint point) { NavMeshHit hit; if (!NavMesh.SamplePosition(point.Position, out hit, 0.2f, 1)) { return; } else { point.Position = hit.position; } var new_ = addPoint(point); if (index >= 0) { _points.LinkRight(index, new_); } index = new_; }
public int Add(SearchPoint point) { Points.Add(point); return(Points.Count - 1); }
private bool shouldApproach(SearchPoint point) { return(Vector3.Dot(point.Normal, point.Position - transform.position) > 0); }