Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Coding a power distributor like Elite Dangerous

Discussion in 'Scripting' started by JamesS0, Jan 21, 2020.

  1. JamesS0

    JamesS0

    Joined:
    Dec 14, 2015
    Posts:
    3
    I would like to code something similar to the power distributor in Elite Dangerous where you have three columns with a total amount of points/power. you can press a button to add a point to a column while maintaining the same amount of available points. For some reason, I can't seem to think of a way to add a point and remove a point from one of the other 2 columns. Does anyone have an idea I could try?
    At the moment I have a 3x3 grid of check boxes. I have maximum 3 points to "Spend". Pressing left would move a point from the right column and put it into the left column. Pressing Up would take from the highest column and add it to the middle column. It's making my brain hurt now.
    If anyone more experienced in programming can give me a nudge in the right direction, I would appreciate it. Thanks.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,519
    Me too!

    Is what you are talking about essentially a fixed amount of resources that can be moved between some number of buckets? Like maybe three coffee beans, and three cups to put them in. Is that the analogy?
     
  3. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
  4. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    Think of them as percent. So you have a finite amount of resources (100%). You increase one (a) and it reduce other (b,c). So basically it's the ratio of a vs b+c.
    1. You increase a and deduce the same amount to the SUM of the rest.
    2. You scale each element of the sum by the ratio of which sum has been reduced.
     
    JamesS0 likes this.
  5. JamesS0

    JamesS0

    Joined:
    Dec 14, 2015
    Posts:
    3
    Yes. That's an adequate analogy!
     
  6. JamesS0

    JamesS0

    Joined:
    Dec 14, 2015
    Posts:
    3
    I like this approach. I think I'll rework my UI design a bit to incorporate this. Thanks.
     
  7. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Think of the three Systems (lets call them 'thrust', 'weapons', and 'shields') as the corners of an equilateral triangle. Your current 'mix' will always reside within that triangle, and defines (via simplified braycentric Interpolation - measure the distance to each corner, and make the distribution as a percentage of how close (the inverse of how distanct) the point lies to each corner measured by the sum of all distances) how much percent each system of the total receives. Whenever you change your Setting, you'll choose one specific system, and move the mix point directly towars that corner. As long as you ensure that the mix point remains inside the triangle, you automatically have the correct values for the other two systems.
     
    Last edited: Jan 22, 2020