bool cast(TankMotor.Ray r, Vector2 pos, float rad, Arena.Obstacle obs) { Vector2 tan = new Vector2(r.Dir.y, -r.Dir.x); Vector2 intersection; float t1, t2; FindIntersection(Motor.Pos, r.Dir, pos, tan, out intersection, out t1, out t2); if (t1 < 0 || Mathf.Abs(t2) > rad) { return(false); } if (t1 - rad > r.RangeMod * Motor.BaseRange * r.Out_Dis) { return(true); } float pen = Mathf.Sqrt(rad * rad - t2 * t2); if (t1 - pen > r.RangeMod * Motor.BaseRange * r.Out_Dis) { return(true); } if (obs != null) { obs.cast(Motor, r); } else { r.Out_Opponent = 1; r.Out_Dis = (t1 - pen) / (r.RangeMod * Motor.BaseRange); } return(true); }
public void cast(TankMotor mtr, TankMotor.Ray r) { //if( c! ) r.Out_Dis = (t1 - pen) / (r.RangeMod * Motor.BaseRange); for (int i = 0, j = Segments.Length - 1; i < Segments.Length; j = i, i++) //todo we could cache index of hit and start at that point next time // var m = (c.points[i] + c.points[j]) * 0.5f; // Gizmos.color = Color.black; // Gizmos.DrawLine(m, m + obs.Tangents[i] * 4); { if (Vector2.Dot(Segments[i].Tan, r.Dir) > 0.0f) { continue; } float d; if (FindIntersection(Segments[i].Pnt, Segments[j].Pnt, mtr.Pos, mtr.Pos + r.Dir * (r.RangeMod * mtr.BaseRange * r.Out_Dis), out d)) { r.Out_Dis *= d; break; } } }