• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 A Game With Navy Ships in It

Vargas

Member
Introduction:
So I've gone through the basic tutorial on Youtube for GMS2 before but I wanted to try something a little more ambitious this time around. Instead of making a small game where you have one objects that flies around, I'm making one where you drive a warship and use multiple turrets on one vehicle at a time.

What I'm Struggling With:
  • Getting a moving sprite of the ship's hull on screen
  • Getting the camera to follow the ship's hull around
  • Multiple speed settings
  • Turning speed proportional to directional speed
  • Mounting multiple moving turrets on the hull sprite.
What I'm Trying to Achieve:
I would like it if all the turrets on the ship would automatically turn (slowly) to face where the mouse is pointing (to a limited extent). Meaning that they are limited to about 220 degrees of freedom each.

While I can currently get one turret to stay centered on the ship by using this code:
Code:
//Keep Turret on ship
x = obj_player.x;
y = obj_player.y;
If I want this ship to have multiple turrets, they will need to be locked to different positions along the length of the hull itself and not just to its center. The points where I'd like to mount the turrets are indicated with a red square:
Hull - Test.png
Here's what I'm currently using for the turret sprite:
Turret 1 - Test.png
Does anyone have any advice?
 

Chaser

Member
find out where those co ordinates are on your ship sprite, and maybe use the same code but modify the sprite co ordinates for each turret?

//Keep Turret 1 on ship
x = obj_player.x+100;
y = obj_player.y+100;

//Keep Turret 2 on ship
x = obj_player.x+200;
y = obj_player.y+200;

//Keep Turret 3 on ship
x = obj_player.x+300;
y = obj_player.y+300;

//Keep Turret 4 on ship
x = obj_player.x+400;
y = obj_player.y+400;

just random + numbers. :)
 

Vargas

Member
find out where those co ordinates are on your ship sprite, and maybe use the same code but modify the sprite co ordinates for each turret?

//Keep Turret 1 on ship
x = obj_player.x+100;
y = obj_player.y+100;

//Keep Turret 2 on ship
x = obj_player.x+200;
y = obj_player.y+200;

//Keep Turret 3 on ship
x = obj_player.x+300;
y = obj_player.y+300;

//Keep Turret 4 on ship
x = obj_player.x+400;
y = obj_player.y+400;

just random + numbers. :)
Thanks! Also, your post just gave me an idea, would it be possible to have one object for the turret be drawn multiple times on the several locations on the hull? Is there a solution using some kind of drawsprite function?
 

Vargas

Member
find out where those co ordinates are on your ship sprite, and maybe use the same code but modify the sprite co ordinates for each turret?

//Keep Turret 1 on ship
x = obj_player.x+100;
y = obj_player.y+100;

//Keep Turret 2 on ship
x = obj_player.x+200;
y = obj_player.y+200;

//Keep Turret 3 on ship
x = obj_player.x+300;
y = obj_player.y+300;

//Keep Turret 4 on ship
x = obj_player.x+400;
y = obj_player.y+400;

just random + numbers. :)
Hey so I tried implementing your solution but this is what happens when I try to turn the ship: https://i.gyazo.com/5808b7539c4f8ecb58f101b6f7b12e52.mp4
 

Chaser

Member
I'm not completely good at coding, :) might work out difficult if having the same object at different places, i think gamemaker will always generate an different Id for each instance, so if you plan on using the code anywhere else it might be hard to find, or not, im not sure, you could maybe the DRAW the same sprite in different locations and have an object created(missiles) from those co ordinates. so yes you could use
Draw_sprite(spr_turret, obj_player.x,obj_player.y)
Draw_sprite(spr_turret, obj_player.x+100,obj_player.y+100)
Draw_sprite(spr_turret, obj_player.x+200,obj_player.y+200)
Draw_sprite(spr_turret, obj_player.x+300,obj_player.y+300)

BUT, you will have no control on how they operate with regards to your movement that you spoke about, they will just run through the animation sequence. :)
I'd just have a object for each turret, least that way you have control, and should allow you to modify one of them easily for other purposes later in game if you decide to do some thing different(like shoot different missiles)
 

Vargas

Member
I'm not completely good at coding, :) might work out difficult if having the same object at different places, i think gamemaker will always generate an different Id for each instance, so if you plan on using the code anywhere else it might be hard to find, or not, im not sure, you could maybe the DRAW the same sprite in different locations and have an object created(missiles) from those co ordinates. so yes you could use
Draw_sprite(spr_turret, obj_player.x,obj_player.y)
Draw_sprite(spr_turret, obj_player.x+100,obj_player.y+100)
Draw_sprite(spr_turret, obj_player.x+200,obj_player.y+200)
Draw_sprite(spr_turret, obj_player.x+300,obj_player.y+300)

BUT, you will have no control on how they operate with regards to your movement that you spoke about, they will just run through the animation sequence. :)
I'd just have a object for each turret, least that way you have control, and should allow you to modify one of them easily for other purposes later in game if you decide to do some thing different(like shoot different missiles)
I tried your offset method but the problem is that it causes the turret to migrate off the hull if I ever turn. I also tried to upload footage of it happening but it didn't work.

What I need is a way to lock the sprite to a certain position on the bigger sprite.
 

Chaser

Member
oh yeah, er, maybe your will have to see how those co ordinates change when the ship is turning and modify the code of the turret coordinates in a step event maybe? as i said, im not the best at code. :)
 

Vargas

Member
oh yeah, er, maybe your will have to see how those co ordinates change when the ship is turning and modify the code of the turret coordinates in a step event maybe? as i said, im not the best at code. :)
Understood, thanks anyways though!
 

Vargas

Member
With the help of my dad, I managed to get it to work:
Code:
//Keep Turret on Ship

obj_turret01.x = obj_player.x + 18*cos(-1*obj_player.image_angle*3.14159/180);
obj_turret01.y = obj_player.y + 18*sin(-1*obj_player.image_angle*3.14159/180);
 

jackquake

Member
Take a look at the lengthdir functions for the same result. They essentially do the hard math for you that you have done manually.
 
Top