• 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!

Need some help!

Z

Zande45

Guest
So I know programming but am a total newbie at game maker studio. I started to make a game without youtube tutorials cause I want it to be more original... Right now, its a top down game of a sailing/fighting. But, theres no fighting yet.. Heres why:

I would like to give the player the option to purchase more guns for their ship.. How would I add guns to it? I played with the draw event and instance_create to no avail.. The guns need to be placed onto the ship object and move with it perfectly.. Or should I make another image of the ship and use image_index?

Future question: How should I make the enemy ship AI? It needs to not just chase the player but turn to the side and orbit, so it can fire the side cannons at the player
 
N

noobhere

Guest
@Zande45 I'd usually prefer to use draw event and instance_create. It's more (seriously) easy to edit. You'd like to have more than one guns equipped so that it combined or just one gun that can be equipped? You can achieve all of that by using it.
 
Z

Zande45

Guest
@Zande45 I'd usually prefer to use draw event and instance_create. It's more (seriously) easy to edit. You'd like to have more than one guns equipped so that it combined or just one gun that can be equipped? You can achieve all of that by using it.
Im thinking it should start with only one cannon on each side and you could add more to it.. At the moment its all simple graphics but im still not sure how to use the draw event or whether to use instance_create_depth or instance_create_layer.. Would it go in the player's create event? Or do I need to add a draw event?
 
N

noobhere

Guest
@Zande45 Mm.. It seems like you want to make an upgrade system instead of purchase more to add? Well if that so, image_index could also be a good choice! Because you could make the image variant when it's come to higher level. e.g. More cannon installed, more magnificent, more bigger.. But different image_index could also change the mask of the sprite, so (if you have a quite-big deal with collision) you should create its own mask.

I'd prefer to use image_index and use custom mask if it's come to an upgrade system, which do better level better image.
 
G

Gillen82

Guest
In the step event for the gun you can update the x and y positions to match the boat/ship

Code:
x = boat.x;
y = boat.y;
 
Last edited by a moderator:
Z

Zande45

Guest
@Zande45 Mm.. It seems like you want to make an upgrade system instead of purchase more to add? Well if that so, image_index could also be a good choice! Because you could make the image variant when it's come to higher level. e.g. More cannon installed, more magnificent, more bigger.. But different image_index could also change the mask of the sprite, so (if you have a quite-big deal with collision) you should create its own mask.

I'd prefer to use image_index and use custom mask if it's come to an upgrade system, which do better level better image.
Thanks for the info! Using the image index seems like itll be easiest like you said cause yes its more like an upgrade system.. Im going to have probably 3 ship sizes so thats not too many collision masks
 
C

CptChuckles

Guest
be sure to erase the space between boat .y; or it won't work

Future question: How should I make the enemy ship AI? It needs to not just chase the player but turn to the side and orbit, so it can fire the side cannons at the player
This is a complex algorithm you're asking for, and we can't give you that because we'd be programming your game for you.
you should come up with how the computer should think about the problem. The only things the computer can know are the positions and angles of the objects, so you need to imagine the thought process that an AI ship would have. Based on your description, you need the computer to think through something like this process:
  • AI ship needs to be n distance from player to fire, with some margin
  • AI ship needs to reach this distance, then rotate to 90 degrees relative to the player to aim the cannon
  • AI ship needs to check that those two conditions are met and then fire
so based on those needs, the AI ship should think like this
  • Subtract AI ship's position from player's position to discover the distance and angle to player
  • If this distance is not the proper range, then move towards or away from the player to reach that range
  • Once AI ship gets into range, check the angle from the AI ship to the player and the current direction of the AI ship
  • This relative angle has to be 90 degrees (assuming the guns are on the sides). Rotate the AI ship until it's facing 90 degrees from player.
  • Once this angle is achieved, fire the cannon
You have to come up with code for this. Come back and ask for help when you encounter bugs or problems that you can't resolve, post your code, and we will help.
 
Z

Zande45

Guest
be sure to erase the space between boat .y; or it won't work


This is a complex algorithm you're asking for, and we can't give you that because we'd be programming your game for you.
you should come up with how the computer should think about the problem. The only things the computer can know are the positions and angles of the objects, so you need to imagine the thought process that an AI ship would have. Based on your description, you need the computer to think through something like this process:
  • AI ship needs to be n distance from player to fire, with some margin
  • AI ship needs to reach this distance, then rotate to 90 degrees relative to the player to aim the cannon
  • AI ship needs to check that those two conditions are met and then fire
so based on those needs, the AI ship should think like this
  • Subtract AI ship's position from player's position to discover the distance and angle to player
  • If this distance is not the proper range, then move towards or away from the player to reach that range
  • Once AI ship gets into range, check the angle from the AI ship to the player and the current direction of the AI ship
  • This relative angle has to be 90 degrees (assuming the guns are on the sides). Rotate the AI ship until it's facing 90 degrees from player.
  • Once this angle is achieved, fire the cannon
You have to come up with code for this. Come back and ask for help when you encounter bugs or problems that you can't resolve, post your code, and we will help.
Thank you! Ill let you know how it goes.. Im used to coding but not with gml, so ill come back with any issues.. The replies have been very helpful, now im not stuck, great community!
 
G

Gillen82

Guest
be sure to erase the space between boat .y; or it won't work


This is a complex algorithm you're asking for, and we can't give you that because we'd be programming your game for you.
you should come up with how the computer should think about the problem. The only things the computer can know are the positions and angles of the objects, so you need to imagine the thought process that an AI ship would have. Based on your description, you need the computer to think through something like this process:
  • AI ship needs to be n distance from player to fire, with some margin
  • AI ship needs to reach this distance, then rotate to 90 degrees relative to the player to aim the cannon
  • AI ship needs to check that those two conditions are met and then fire
so based on those needs, the AI ship should think like this
  • Subtract AI ship's position from player's position to discover the distance and angle to player
  • If this distance is not the proper range, then move towards or away from the player to reach that range
  • Once AI ship gets into range, check the angle from the AI ship to the player and the current direction of the AI ship
  • This relative angle has to be 90 degrees (assuming the guns are on the sides). Rotate the AI ship until it's facing 90 degrees from player.
  • Once this angle is achieved, fire the cannon
You have to come up with code for this. Come back and ask for help when you encounter bugs or problems that you can't resolve, post your code, and we will help.
Didn't realize I put the space in. Corrected it. Cheers!!
 
Z

Zande45

Guest
This is a complex algorithm you're asking for, and we can't give you that because we'd be programming your game for you.
you should come up with how the computer should think about the problem. The only things the computer can know are the positions and angles of the objects, so you need to imagine the thought process that an AI ship would have. Based on your description, you need the computer to think through something like this process:
  • AI ship needs to be n distance from player to fire, with some margin
  • AI ship needs to reach this distance, then rotate to 90 degrees relative to the player to aim the cannon
  • AI ship needs to check that those two conditions are met and then fire
so based on those needs, the AI ship should think like this
  • Subtract AI ship's position from player's position to discover the distance and angle to player
  • If this distance is not the proper range, then move towards or away from the player to reach that range
  • Once AI ship gets into range, check the angle from the AI ship to the player and the current direction of the AI ship
  • This relative angle has to be 90 degrees (assuming the guns are on the sides). Rotate the AI ship until it's facing 90 degrees from player.
  • Once this angle is achieved, fire the cannon
You have to come up with code for this. Come back and ask for help when you encounter bugs or problems that you can't resolve, post your code, and we will help.
Hello again, maybe you could help me out with my new problem.. So I got all the guns and shooting working, and now im working on the enemy AI it can do everything I want but I wish it was better at turning so the cannons face the player.. You mentioned rotating 90 degrees relative to the player, how would you do that? The way I did it doesn't seem to work that well.. Is there some kind of aiming line that could extend from the sides of the ship, so I could check if the sides are facing the player?
 
Z

Zande45

Guest
@noobhere Hello again! Maybe you could help me with a problem ive ran into.. So I got the guns all done, they fire correctly from the sides and theres an animation.. Now im working on the enemy AI and ive got it to chase the player and turn so the cannon will face it.. Now it needs to fire, but I can't figure out how to tell the AI which side to fire from. How should it detect what side the player is closest to?.. Ive tried using the x and y axis and also checking what angle the player is at, but when the ships are circling each other it fires from the opposite side sometimes and I don't know why
 
N

noobhere

Guest
@Zande45 Sorry for my very late reply. So.. you got the guns all done and there was an animation and now working on AI? Cool! How fast your progress with gml!

Am I get myself clear, you want to come up with checking something that would decide which side is nearest to the player position so it could turn at the most effective? Well, looks like you've used point_direction?
ive got it to chase the player and turn so the cannon will face it..
It could be useful with something about angle difference. I'll give it a try.. wait..
 
N

noobhere

Guest
@Zande45 Well this was very interesting case! Really challenged me for a while, thanks for that, I love challenge! Here's mine:
The sprite at angle 0:
upload_2018-7-28_13-56-50.png
The code:
Code:
/// CREATE EVENT
side = 0;
/// STEP EVENT
targetX = mouse_x;
targetY = mouse_y;
pointDir = point_direction(x,y,targetX,targetY);
side1Dif = angle_difference(image_angle-90,pointDir);
side2Dif = angle_difference(image_angle+90,pointDir);
if(abs(side1Dif) < abs(side2Dif))
{
 side = 1; // right
 angleDif = (pointDir+90)-image_angle;
 image_angle += sin(degtorad(angleDif))*5;
}
if(abs(side1Dif) > abs(side2Dif))
{
 side = 2; // left
 angleDif = (pointDir-90)-image_angle;
 image_angle += sin(degtorad(angleDif))*5;
}
/// angle_difference SCRIPT
return (((((argument0-argument1) mod 360)+540) mod 360)-180);
Actually GM 2 has built-in angle_difference:
There is a function built in to do angle differences
@Morendral Mm.. what's that? (I'm using GM 1.4)
In that case, make a custom script for yourself

http://www.gmlscripts.com/script/angle_difference
He just helped me through my issue https://forum.yoyogames.com/index.php?threads/solved-track-angle-dif-for-drag-and-swing-sword.50397/. So am I did it? Am I make myself clear?
 
Top