2
\$\begingroup\$

I'm designing a game that involves the simulation of a breadboard. I would like some advice on the best way to simulate jumper wires used to connect various places on the breadboard together. I have provided a picture below for those unfamiliar with electronics.

enter image description here

These are the wires I would like to simulate. I would like them to dynamically adjust in length based on the distance of the connection points, and with some randomness (so hopefully wihout a perfect curve from point A to B). To be clear, the wires to not need to move dynamically, they just need to generate once.

If realistic randomness is not possible, what would be the best way to achieve even something like a smooth curve of wire from point A to B?

\$\endgroup\$
4
  • \$\begingroup\$ Not an easy one as it depends very much on what you consider to be the "right" look. Generally, Bezier curve segments would be used, however being non-linear, they can be more difficult to work with in certain cases. Simulating the bendability of the wire is another way to go. You could use linearly-spaced segments with a maximum bend factor at each joint vertex. This means where the connecteor comes out, you won't have an immediate bend. The issue is then targeting the opposing endpoint, such that the wire hooks up, which brings to mind inverse kinematics - google for more. \$\endgroup\$ Commented Mar 2, 2021 at 8:02
  • \$\begingroup\$ @Engineer Thanks for all the pointers! This seems like a quite complicated implementation path, do you know of any pre-existing plugins or addons for Unity which may be able to achieve something like what I'm looking for? \$\endgroup\$ Commented Mar 2, 2021 at 8:08
  • \$\begingroup\$ I'm sure there must be something on the Unity store that does this... albeit in 2D rather than 3D? The principles, incidentally, would be the same. \$\endgroup\$ Commented Mar 2, 2021 at 8:13
  • \$\begingroup\$ Perhaps it would be a good angle to approach this as rope physics? \$\endgroup\$ Commented Mar 2, 2021 at 8:55

1 Answer 1

2
\$\begingroup\$

Assuming only breadboard connection points which go straight down into the board (and at no other angle, such as connectors off to the side of the breadboard), there is a simple solution. Note that here I am talking only about the points needed to create the core of the wire path, not the renderable geometry itself.

First, consider the board top down and draw straight lines between the connection points. This step enables you to determine potential wire crossings. Add any unique crossed pairs to a list, for checking against one another, later.

Now, viewed side-on, you want to avoid crossings AND have a more wirelike (curved) profile, such that the connection curves from point A on the board, up, over and down to point B.

So what we do is to take that line and turn it into a semi-circle. (Formulae for getting points on a circle at various incremental radii can be found all over the internet.)

Great. Since most pairs of connections will not have the same length (in 2D), then even if these intersect on the top-down drawing, they usually (!) will not intersect side-on, because the different lengths lead to different radii which lead to different wire curvature.

If intersections of wires matter to you...

However, in some cases you may have an intersection. Though these will be rare (and rarer the thinner the final wire geometry is), if this does matter to you, you will need to check all cylindrical segments of each pair stored above, against one another, and determine if there are intersections - this could be costly, but it sounds like you are building your wires once-off. What you need to do here is scale the set of semi-circular vertices such that is is more elliptic. This perturbation needs to occur until they no longer intersect. To check whether two wires intersect, consider the diagram from top-down again: if the height of the two arcs is the same where the two 2D / overhead lines intersect, then you need to shift one or the other arc, accordingly.

Final cosmetic effects

Note that making these curves more elliptic may also be something you do just to get every wire looking a bit different, so it's not all too uniform. As a bonus step, you could also, instead of just using a semi-circle across the distance, use two rounded corners going down into the breadboard, and a straight section between.

Beyond this, with linear segments, perturbations etc. are yours to make as you wish, for example if you wanted a wire to look like it had been fiddled with by hand.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks! Which type of object would be the best way of getting started generating the actual wire? A line renderer? \$\endgroup\$ Commented Mar 3, 2021 at 5:19
  • \$\begingroup\$ @skillz21 If you want it to look 3D with 3D lighting, you'll need to position spheres at each of the interstice points you've generated above, and then lay cylinders (correctly aligned) midway between them. The more interstices per curve, the more realistic it will look. The sphere just prevent sharp angles between the cylinders making up the actual segments. \$\endgroup\$ Commented Mar 3, 2021 at 15:33
  • \$\begingroup\$ At a later stage, for improved performance (fewer GameObjects), I would consider generating a single custom mesh for each wire. You could alternative pre-generate a set of wires of different lengths, at startup time, and then pick from these at runtime. \$\endgroup\$ Commented Mar 3, 2021 at 15:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.