• 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 [Solved] multiple instances problem

Dupletor

Member
[Solved]
I need to keep many fishes in a moving aquarium.
The Aquarium has a fish house in it. It has to be positioned in the Aquarium center, always.
For this, through the house, I track the aquarium position differentiation, and add it to each fish.

Code:
diffx = x;
diffy = y;

x = Aquarium.x + Aquarium.sprite_width/2;
y = Aquarium.y + Aquarium.sprite_height/2;

diffx -= x;
diffy -= y;

with(Fish){
     x -= other.diffx;
     y -= other.diffy;
}
This code works if the aquarium has 1 fish, and the fish moves with the aquarium. However, for some reason, if it has 2 fish, each fish starts moving twice as fast, and I have no idea why.

[EDIT: SOLVED]
It was solved because I noticed every fish had one house, and the problem was not that there were multiple fish, but that there were multiple houses, all of them interfering with every fish.
Then I edited again because I found it was not a full solution.
But then I couldn't reproduce the problem and it solved itself. :confused:
Well... Sorry. :D
 
Last edited:
K

kevins_office

Guest
I need more information.
What object is that code running in?
Why are you setting x and y of this unknown object to aquarium center?

I suspect you need to have this code part of the code that moves the aquarium, because you would need to know the fishes position before the aquarium moves so you can create an offset value of the fish to the aquarium.
Then after the aquarium moves you apply the offset amount back to the fish so its in the same place relative to the moved aquarium.
 
Top