public override void Draw() { base.Draw(); var delta = End - Position; float len = delta.magnitude; var dir = delta.normalized; float angSin = Mathf.Sin(Mathf.Deg2Rad * Angle); float radius = angSin * len; Handles.color = Color; if (Period > 0) { for (float dist = Period; dist < len; dist += Period) { Handles.DrawWireDisc(Position + dir * dist, dir, angSin * dist); } } Handles.DrawWireDisc(End, dir, radius); if (DrawLines) { var perpendicular1 = Vector3.Cross(dir, Vector3.up).normalized; var perp2d = Vector2.Perpendicular(new Vector2(dir.x, dir.z)); var perpendicular2 = Vector3.Cross(dir, new Vector3(perp2d.x, 0, perp2d.y)).normalized; Handles.DrawLine(Position, End + perpendicular1 * radius); Handles.DrawLine(Position, End - perpendicular1 * radius); Handles.DrawLine(Position, End + perpendicular2 * radius); Handles.DrawLine(Position, End - perpendicular2 * radius); } }
private Vector2 GetEndPoint() { Vector2 direction = Target.Center - Source.Center; Vector2 normalizedDirection = direction.normalized; Vector2 perpendicular = Vector2.Perpendicular(normalizedDirection); return(Target.Center + (perpendicular * LineOffset)); }
private Vector2 GetStartPoint() { Vector2 direction = Target.Center - Source.Center; Vector2 normalizedDirection = direction.normalized; Vector2 perpendicular = Vector2.Perpendicular(normalizedDirection); return(Source.Center + (perpendicular * 7)); }
private void OnMoveDirectionChanged(Vector2 direction) { rayDirection = direction; var normalVector = Vector2.Perpendicular(direction); rayPointOffset = normalVector * Config.BallRadius; rayPointDisplacement = direction * (Config.BallSpeed * Time.fixedDeltaTime); CheckCollision(); }
private void DrawArrow(Vector2 center, Vector2 direction) { Vector2 normalizedDirection = direction.normalized; var perpendicular = Vector2.Perpendicular(direction) * -1; var inferiorLeftPoint = center + (perpendicular.normalized * ArrowWidthExtent) - (normalizedDirection * ArrowHeightExtent); var inferiorRightPoint = center - (perpendicular.normalized * ArrowWidthExtent) - (normalizedDirection * ArrowHeightExtent); var superiorPoint = center + (normalizedDirection * ArrowHeightExtent); Handles.DrawAAConvexPolygon(superiorPoint, inferiorLeftPoint, inferiorRightPoint, superiorPoint); }
Vector2 RelativePitchToTarget(Vector2 target, float pitchDegrees, float deadRange = 5) { Vector2 turnForce = Vector2.Perpendicular(rb.velocity) / rb.mass; float angleToTarget = Vector2.Angle(rb.velocity, target - getPosition()); float direction = 1; if (angleToTarget > 180) { angleToTarget = 360 - angleToTarget; direction = -1; } if (pitchDegrees + deadRange < angleToTarget || angleToTarget < pitchDegrees - deadRange) { return(turnForce * direction); } else { return(Vector2.zero); } }
public override void Draw() { base.Draw(); var delta = End - Position; float len = delta.magnitude; var dir = delta.normalized; float angSin = Mathf.Sin(Mathf.Deg2Rad * Angle); float radius = angSin * len; Handles.color = Color; var perp2d = Vector2.Perpendicular(new Vector2(dir.x, dir.z)); var perpendicular = Vector3.Cross(dir, new Vector3(perp2d.x, 0, perp2d.y)).normalized; var start = Quaternion.AngleAxis(-Angle * 0.5f, perpendicular) * dir; var end = Quaternion.AngleAxis(Angle * 0.5f, perpendicular) * dir; Handles.DrawWireArc(Position, perpendicular, start, Angle, len); Handles.DrawLine(Position, Position + start * len); Handles.DrawLine(Position, Position + end * len); }