Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by lciferri · Dec 08, 2016 at 06:44 AM · gridpower

How to model electrical grid/power grid?

I am currently trying to make a simple game where various piece must be connected to form a circuit. there are pieces that generates electricity, pieces that simply conduct it and pieces that consume it.

Each object have a stat called PowerGeneration. Generator have a PowerGeneration= +X, conductors PowerGeneration= 0 (or -0,1 to account for losses of power due to ohmic resistance) and consumer such as motors have PowerGeneration= -2 or higher values. But i can't really think of a way to "limit" the consumption based on the generator.

Do you have any suggestion how to handle the thing?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlwaysSunny · Dec 09, 2016 at 05:34 AM 0
Share

I can't deter$$anonymous$$e what's being asked. What do you mean by "limit the consumption based on the generator"? From what you describe, it sounds like that's exactly what the negative PowerGeneration variable does already. Can you try to clarify the problem?

avatar image lciferri AlwaysSunny · Dec 09, 2016 at 09:15 AM 0
Share

i am trying to implement some kind of power grid in my game. something like "SimCity" where power plant had to power various houses/utilities. there will be some player-placeable generators and consumers. what i want to do is that , for every grid, the script check continually every consumer and generator and adds the "PowerGeneration" value, at the end of the cycle if the PowerGeneration value is <0, then the script must return an error. "Grid XX overloaded"

Problem is that i must calculate the sum for every "electrical grid".so, if 2 generators are on 2 different grids (basically 2 circuit never connected between them), they must calculate the usage only based on the effective consumer on that specific grid. the biggest problem is that the player can make a variable number of grid and connect/disconnect them afterwards, it that case, 2 different grids must merge/divide accordingly.

avatar image AlwaysSunny lciferri · Dec 09, 2016 at 03:42 PM 0
Share

replied via answer

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by AlwaysSunny · Dec 09, 2016 at 03:42 PM

Ah, now I grasp what you're wanting. As with all things, there are many ways to handle this. The "best" way would be optimized to account for a potentially huge number of objects, and would be directly integrated with any other systems that work in a similar way (water, traffic, etc) but that is actually a very substantial topic.

Managing a small network (~250 objects) is much simpler, because you can almost ignore optimization (spreading the job of power calculation over multiple frames) and just use the most obvious approach (doing it all in a single frame). If you're eventually wanting many hundreds or thousands of objects in a single network, you'll need to do some serious research into organization / optimization of complex networks / data sets.

The first optimization that comes to mind is a structure which sub-divides a logical network (like each individual power grid) into "chunks" to examine each chunk individually. Thus the whole network (any network: power, water, traffic) is only updated every X frames, where X is the total number of chunks. (I'm fairly confident this is how most systems in most city simulator games distribute work, but they're probably also multi-threading.) But that's getting really deep, and you can totally ignore this depth unless you need that optimization to keep the game running at your target FPS.

Are you planning on a grid-based approach to everything like ANNO, or a freeform approach like Cities:Skylines? A grid-based approach is convenient because you'll already have a data set that is directly related to the logic of other systems (power, water, etc).

I've never done anything quite like this, but there are some logical first steps. I can't tell your level of programming experience so this may sound obvious, but it's very wise to keep collections of any instantiated objects as they are created / destroyed. So your map manager will presumably have a collection of buildings / structures, some of which will participate in the power-logic layer.

When these objects are added or removed from the scene, also add / remove them from a collection of powered_objects. The power (water, traffic,) network(s) will examine only those objects relevant to them so you can safely ignore the rest.

With this in mind, you have to make your own informed decision about the best way to represent your network. I've only ever worked with simple networks of tiles where they are un/walkable, but what you're doing is kind of similar. You want to check that every power-consuming object is connected via an imaginary wire to a power-producing object.

I can't comment much on the best way to represent your networks without knowing more about the game. But however you go about doing so, you'll want a collection of networks (fulfilling the requirement of separate independent networks) and each network has a collection of its power_producers and power_consumers. Then you can just keep a running tally of their consumption / production (as they are added, removed, activated, deactivated) and do a simple difference check.

We can talk more about how to actually network them if you want, but I'll need to understand more about your game and how it's structured.

RSVP or good luck,

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

GetComponent not working on GridLayoutGroup 2 Answers

2D Board game grid placement 0 Answers

I need to get a Vector3 of the mouse position while i'm editing in the scene view. 2 Answers

How Can I Create a Button that Takes Multiple Objects and cycles them through a grid? (Unity 2D) 0 Answers

Code for gridColour[x,y] == gridColour[x+1,y] || colour at [x-1,y] || colour at [x,y+1] ||colour at [x, y-1] to detect if 4 of the same colours are connected? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges