Splitting Sum between to objects?

This forum is currently in read-only mode.
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hey, I'm having a **ll of a time trying to split a value between to objects.

    If one object weighs 100 and the other object weighs 100, then my value should get split evenly between them.

    If one object weighs 200 and the other object weighs 100, then the 200 weight object gets 25% of the value and the 100 weight object get 75% of the value.

    How do I do this?

    All help is appreciated.

  • Um Im gonna say ((weighta + weightb) + newweight)/2= newweighta + newweightb

  • That would just give half of the sum to each object, I need it to be different for each object based on the difference between two values. Any ideas?

  • you are talking about dividing the new weight depending on the difference between the original weights, so with 200 to 100, the difference would be 100 / 0. in this case, you state you want a division of 25 / 75 percent. for 0 / 0, it should be 50 / 50. that sounds like the unbiased percentage of 50 is halfed for every 100 weight-units an object weights more than its counterpart. i think that is an exponential function ...

    myWeight = 200;
    otherWeight = 100;
    newWeight = x;
    myBias = abs( myWeight - otherWeight ); // the weight bias
    myBias *=( Sign( myWeight - otherWeight )> 0 ); // if its negative, make it zero
    if( myBias != 0 )
        myPercent = .5 ^( myBias / 100 );
    else
        myPercent = 1 - otherPercent;
    myWeight += newWeight * myPercent;[/code:i1z7khp6]
    something like that, i guess; it could be merged into one line, but that would just be confusing. unless you really wanted the division to respect the [i]relative[/i] weights of the objects, which would be simpler.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks but I gpt it last night (came to me while I was brushing my teeth)

    1-(object1.Value('weight')/(object1.Value('weight')+object2.Value('weight')))

    (object1.Value('weight')+object2.Value('weight')) makes the base then dividing that by object1's weight give the percentage of the total, then subracting it from 1 make the heavier object affected less.

    Thanks for all the help.

  • You definitely should brush your teeth more often

  • yeah, I think I will.

  • i'm glad you found a solution that works for you, but be aware that this does not really do what you asked for in your first post ( with 200 / 100, you'll get a 33 / 66 percent split ) </nitpick> :)

  • that's right, thanks for pointint that out (it's actually what I want)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)