private SteeringOut ObstacleAvoidance(LayerMask obstDef) { SteeringOut steeringOut = new SteeringOut(); RaycastHit2D rcHit = Physics2D.Raycast(_owner.Position, _owner.VectorHeading(), _owner.obsFeelerLen, obstDef); /* Draw feeler * Debug.DrawRay (_owner.Position, new Vector3 (_owner.VectorHeading().x, * _owner.VectorHeading ().y, 0) * _owner.obsFeelerLen, Color.green); */ if (rcHit.collider == null) { return(steeringOut); } Vector2 toObst = (Vector2)rcHit.transform.position - _owner.Position; float toObstDeltaAngle = Utils.DeltaAngle(_owner.DegreeHeading(), Utils.Vector2Angle(toObst)); float newTargetAngle = _owner.DegreeHeading(); if (toObstDeltaAngle < 0) { newTargetAngle = newTargetAngle + 90 + toObstDeltaAngle; } else { newTargetAngle = newTargetAngle - 90 + toObstDeltaAngle; } float deltaAngle = Utils.AbsDeltaAngle(newTargetAngle, _owner.DegreeHeading()); steeringOut.LimitSpeed = DeltaAngle2LimitSpeed(deltaAngle); steeringOut.TargetAngle = newTargetAngle; return(steeringOut); }