• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Math problem

M

Midastouch

Guest
Hello everyone,
I have a little math problem.

I have 2 volumes of water (each volumes of water can have a value between 0 and 100).

The volume 2 go down on the volume 1. The volume 1 is on the ground.
When both of these volumes meet i want to recalculate the volume of water in each of these volumes.

For exemple :
if volume 1 = 25
if volume 2 = 100
So
volume 1 = 100
volume 2 = 25

For exemple :
if volume 1 = 50
if volume 2 = 50
So
volume 1 = 100
volume 2 = 0

For exemple :
if volume 1 = 75
if volume 2 = 25
So
volume 1 = 100
volume 2 = 0

For exemple :
if volume 1 = 25
if volume 2 = 25
So
volume 1 = 50
volume 2 = 0
 
M

Midastouch

Guest
Maybe this can works?
GML:
A = volume 1 + volume 2


if A > 100 {
    volume 1 = 100
    volume 2 = A-100}

if A <= 100 {
    instance_destroy(object_volume 2)
    volume 1 = volume 1 + volume 2}
 
M

Midastouch

Guest
GML:
var max_to_transfer = 100-volume1;
var transfer = min(max_to_transfer, volume2);
volume1 += transfer;
volume2 -= transfer;
I did this :
GML:
if place_meeting(x,y-1,a1){
    var A
    A = amount_of_water + a1.amount_of_water
    if A > 100 {
        amount_of_water = 100
        a1.amount_of_water = A-100}
    if A <= 100 {
        amount_of_water = amount_of_water + a1.amount_of_water
        instance_destroy(a1)
}}
But your idea is better for my final project thank you
 
Top