protected override bool magnetic_effect(Magnetic_Object magnetic_object) { this.effective_range.sync_centre(this.rigidbody.position); float distance = Line.Distance(magnetic_object.rigidbody.position, this.effective_range.line); Vector2 direction = this.effective_range.line.normal_vector * this.pole * magnetic_object.pole; float angle = Vector2.Angle(direction, new Vector2(0, 1)); if (distance > this.effective_range.max_range) { return(false); } else { if (!Line.Inside_Line(magnetic_object.rigidbody.position - distance * this.effective_range.line.normal_vector, this.effective_range.line)) { return(false); } } magnetic_object.force += this.effective_range.k * (1 - distance * distance / this.effective_range.max_range / this.effective_range.max_range) * direction; magnetic_object.d1 = direction; magnetic_object.d2 = this.effective_range.k; //magnetic_object.d3 = sign; magnetic_object.d4 = distance; return(true); }
public bool remove_magnetic_object(Magnetic_Object magnetic_object) { try { this.magnetic_objects.Remove(magnetic_object); this.magnet_num = this.magnetic_objects.Count; } catch { return(false); } //MonoBehaviour.print("added"); return(true); }
protected override bool magnetic_effect(Magnetic_Object magnetic_object) { this.effective_range.sync_centre(this.rigidbody.position); float distance = Vector2.Distance(this.effective_range.centre, magnetic_object.rigidbody.position); Vector2 direction = (magnetic_object.rigidbody.position - this.effective_range.centre).normalized * this.pole * magnetic_object.pole; float angle = Vector2.Angle(direction, new Vector2(0, 1)); float sign; if (direction.x != 0) { sign = direction.x / Mathf.Abs(direction.x); } else { sign = 1; } float angle_range = Vector2.Angle(this.effective_range.start_edge, this.effective_range.end_edge); if (distance > this.effective_range.max_radius) { return(false); } else { if (this.effective_range.minor_arc) { if (Vector2.Angle(direction, this.effective_range.start_edge) > angle_range || Vector2.Angle(direction, this.effective_range.end_edge) > angle_range) { return(false); } } else { if (Vector2.Angle(direction, this.effective_range.start_edge) < angle_range && Vector2.Angle(direction, this.effective_range.end_edge) < angle_range) { return(false); } } } direction = new Vector2(sign * Mathf.Sin(Mathf.Round(angle * this.effective_range.resolation) * this.effective_range.precision), Mathf.Cos(Mathf.Round(angle * this.effective_range.resolation) * this.effective_range.precision)).normalized; magnetic_object.force += this.effective_range.k * (1 - distance * distance / this.effective_range.max_radius / this.effective_range.max_radius) * direction; magnetic_object.d1 = direction; magnetic_object.d2 = this.effective_range.k; magnetic_object.d3 = sign; magnetic_object.d4 = distance; return(true); }
protected abstract bool magnetic_effect(Magnetic_Object magnetic_object);
protected bool effection(Magnetic_Object magnetic_object) //应写一个异常 { return(effective_delegate(magnetic_object)); }