Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to simulate electrical flow

Discussion in 'Scripting' started by danikanama, Sep 30, 2020.

  1. danikanama

    danikanama

    Joined:
    Jul 14, 2019
    Posts:
    3
    im trying to make and electrical game with wires and i cant think of way to make a flow logic , any help ?
    the game is 2d and im using colliders to detect connected wires
     
  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    If you're not sure how to model this at all, I'm afraid there is no easy way that can be explained in a few sentences. I would never use colliders for such a task, as you need a more robust model that isn't physics based, but entirely logic based, and you need dedicated algorithms in place to work out the circuit potentials and flows. Electrical circuits are especially tricky, because they don't behave like water, so there could be also things that seemingly violate causality, a faulty model is likely to produce flickering behaviors and oscillations whereas in reality this would be a stable configuration. Of course, if you want to produce something simpler, but just reminiscent of electrical wiring, you can do that just fine, but try to explain a little bit more of it.
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Your question is too vague to answer really. "An electrical game with wires" could mean anything from a realistic electrical circuit simulation with capacitors, resistors, etc.. to... well... the old Bioshock hacking minigame, to... Factorio?

    Could you get more specific?
     
  4. danikanama

    danikanama

    Joined:
    Jul 14, 2019
    Posts:
    3
    "realistic electrical circuit simulation with capacitors, resistors, etc.. " the ultimate goal , is to have many levels on many difficulties, starting with basics and later all sorts of calculations regarding power consumption and energy transfer

    currently im using colliders on each wire and contact , if the power source is on and connected , the wires have a bool isCharged , it works pretty well but im not sure if this system is good enough for the future content of the game, wats,volts,amper,capacitors, resistors, etc..
     
  5. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    oh wow, well you'll have to come up with a concrete question with regards to one single issue you've encountered. we can't surely design the whole electric circuitry simulator for you, nor it is particularly easy to come up with. whether the wiring is connecting is the least of your problems, truth be told.
     
  6. danikanama

    danikanama

    Joined:
    Jul 14, 2019
    Posts:
    3
    yeah mad i get that XD my question was if there is a solid tested way to create the wire system itself .
    i have a progress with colliders system and logic for the wires .
    and later on ill think bout all the details and calculations.
    but im a newbie so if there is a different more efficient way ill be glad to hear :)