Windows I need help with my fish game.

D

Davidblackberry1

Guest
So I am making a fish game that is basically like Insaniquarium, but built in GameMaker. The problem seems to be that the fish are being dumb and run into walls (they are in a tank looking map enclosed with invisible borders) and will not do anything I would like them to do, they just ram into the wall as soon as the game starts. I am trying to direct them to turn around when they get to close to the wall, but it does not seem to be working. I'd also like to have them do a turn animation just once when they change direction (and they are animated btw).
 
D

Davidblackberry1

Guest
///Move The Fish At Random
//Start Moving Fish
if random_range(1,2) == 1{
phy_position_x += 4
}
else{
phy_position_x+= -4
}
//Stop Fishing From Hitting Wall
if phy_position_x >= 600{
phy_position_x += -4
}
if phy_position_x <= 40{
phy_position_x += 4
}

Sorry that code is separate, forgot to paste it in the first place. xD
 
D

Davidblackberry1

Guest
Also, I'm trying to tie fish speed to swim animation speed (image_index), how do I get the speed at which someone is traveling in number form? Example: velocity * 5 = image_index EDIT: I think it is simply "speed" for getting how fast something is going.
 

Brodie

Member
///Move The Fish At Random
//Start Moving Fish
if random_range(1,2) == 1{
phy_position_x += 4
}
else{
phy_position_x+= -4
}
//Stop Fishing From Hitting Wall
if phy_position_x >= 600{
phy_position_x += -4
}
if phy_position_x <= 40{
phy_position_x += 4
}

Sorry that code is separate, forgot to paste it in the first place. xD
I don't have any experience with the physics system in GM, but it looks like, when the fish hit the wall, they are only being moved slightly away from it without changing their direction. Add a line of code to change the object's direction.

Also, random_range(1,2) will randomly choose a number between 1 and 2, including all decimal places. In that case, you will almost never get random_range(1,2) == 1. Consider changing it to choose(1,2) == 1.
 

Brodie

Member
Also, I'm trying to tie fish speed to swim animation speed (image_index), how do I get the speed at which someone is traveling in number form? Example: velocity * 5 = image_index EDIT: I think it is simply "speed" for getting how fast something is going.
It sounds like the built-in "speed" variable is what you're looking for. So you could do something like,
Code:
image_speed = speed/maxSpeed; // where maxSpeed is a variable you set as the maximum speed you want to allow
 
D

Davidblackberry1

Guest
I don't have any experience with the physics system in GM, but it looks like, when the fish hit the wall, they are only being moved slightly away from it without changing their direction. Add a line of code to change the object's direction.

Also, random_range(1,2) will randomly choose a number between 1 and 2, including all decimal places. In that case, you will almost never get random_range(1,2) == 1. Consider changing it to choose(1,2) == 1.
I am pretty sure that if it is moving at a speed of 4 to the left (phy_position_x = -4) and I change that to it moving to the right at a speed of 4 (phy_position_x = 4) then it will override that, and it will start traveling in the opposite direction. Either that or it will add on to it (4 + -4 = 0) and stop it from moving altogether.
 
D

Davidblackberry1

Guest
I'm trying to use the speed variable for something.

image_index = speed * 5

The fish is not animating at all now.
 
D

Davidblackberry1

Guest
Oops, I was thinking of image_speed when I thought of image_index.
 
D

Davidblackberry1

Guest
Oh goodness, why are they dancing now?

image_speed = speed * 5
 

Brodie

Member
I am pretty sure that if it is moving at a speed of 4 to the left (phy_position_x = -4) and I change that to it moving to the right at a speed of 4 (phy_position_x = 4) then it will override that, and it will start traveling in the opposite direction. Either that or it will add on to it (4 + -4 = 0) and stop it from moving altogether.
It sounds like you are mixing up phy_position_x with phy_speed_x. Swap those out and you should be on the right path.
https://docs.yoyogames.com/source/d...ce/physics/physics variables/phy_speed_x.html
 
D

Davidblackberry1

Guest
It appears that choose is choosing way more then I would like it to, every single step.

///Move The Fish At Random
//Start Moving Fish
if choose(1,2) == 1{
phy_position_x += 4
}
else{
phy_position_x+= -4
}
//Stop Fishing From Hitting Wall
if phy_position_x >= 600{
phy_position_x += -4
}
if phy_position_x <= 40{
phy_position_x += 4
}

//Link speed To image_index
image_speed = speed * 5
 
D

Davidblackberry1

Guest
Alright, I switched that stuff out, and now they are backing up a little bit so they can ram into the wall again.
 
D

Davidblackberry1

Guest
At least there is a speck of intelligence with the AI now.
 
D

Davidblackberry1

Guest
I am still having an issue tying the speed to the image_speed.

///Move The Fish At Random
//Start Moving Fish
if choose(1,2) == 1{
phy_speed_x += 2
}
else{
phy_speed_x+= -2
}
//Stop Fishing From Hitting Wall
if phy_position_x >= 600{
phy_speed_x += -2
}
if phy_position_x <= 40{
phy_speed_x += 2
}

//Link speed To image_index
image_speed = speed * 5

Also, watching my fish repeatably bang themselves against the wall is making me uneasy.
 

Brodie

Member
I am still having an issue tying the speed to the image_speed.

///Move The Fish At Random
//Start Moving Fish
if choose(1,2) == 1{
phy_speed_x += 2
}
else{
phy_speed_x+= -2
}
You need to either put the above code in your 'create' event or use a conditional to have it only run once in your step event, otherwise, as you say, the direction will be randomized every step.

//Link speed To image_index
image_speed = speed * 5
This will likely set the animation speed to be much too fast. Because you are using the physics system, you may want to use phy_speed instead of speed. Try something like "image_speed = phy_speed / 2;" and tweak from there.
 
Top