GameMaker: Studio

GameMaker: Studio

View Stats:
smill Oct 31, 2016 @ 10:19am
Line Collisions
I have a turret that shoots at the player.

draw_line_width(id.x,id.y,targetx,targety,8)

targetx and targety are the coordinates of the player. When I had two turrets, I had to modify the start positions (id.x and id.y), by using the following code:

with obj_turret {
if(place_meeting(x,y,obj_turret)) {
return id;
}
}

But the main issue is making the line stop at walls. They are not solid objects but that doesn't matter because the line is a mask not an object. How would I go about walls stopping the laser?

Last edited by smill; Oct 31, 2016 @ 11:35am
< >
Showing 1-6 of 6 comments
BOYCOTT S-T-E-A-M! Oct 31, 2016 @ 11:45am 
You could use the function 'collision_line' to first check for collisions.

With that function you could check for collisions with walls along the line from the turret to the player. If there are no collisions then it has a clear shot and you can draw your line from the turret to the player.

In the case of there being a collision with the wall you could either just have it not shoot or instead draw its line only from the turret to the wall so simulate it hitting the wall.
Last edited by BOYCOTT S-T-E-A-M!; Oct 31, 2016 @ 11:48am
smill Oct 31, 2016 @ 1:42pm 
Yeah that is what I tried to do, but I always got an error when setting the id.x and id.y to something different. I will try to figure it out, thanks for the help :)
If the code ...
draw_line_width(id.x,id.y,targetx,targety,8)
... that you posted is in the turret object and you're using id.x and id.y to refer to the turrets x/y coordinates then you could simplify it by just using x and y.

What error message are you getting?
Diveyoc Oct 31, 2016 @ 7:19pm 
So your turret doesn't have bullets, or it's just like a solid laser beam or something?
If that's the case, you might just create a rapid fire bullet, that is firing so fast it looks like a solid line. That way you could destroy each instance with a wall collision event, and it would still look like a solid laser line.
Last edited by Diveyoc; Oct 31, 2016 @ 7:19pm
smill Nov 1, 2016 @ 12:47pm 
Originally posted by BOYCOTT S-T-E-A-M!:
If the code ...
draw_line_width(id.x,id.y,targetx,targety,8)
... that you posted is in the turret object and you're using id.x and id.y to refer to the turrets x/y coordinates then you could simplify it by just using x and y.

What error message are you getting?
I had to use id.x and id.y because if there were more than 1 turret in the room, the laser beams (which are separate objects) would always draw from just one of the objects. So this would see what turret they are touching and use that as a starting point of the line.
I assume the turrets create an instance of the laser beam object when they fire? If so, why not just along the id of the turret making it and the id of the target (player object I'm assuming) when you create it?

Something like...
inst = instance_create(x, y, obj_laser) with (inst) { owner = other.id target = other.target }



Alternatively, if your laser beam is just a line that goes from the turret to the player you could just not have it be an object at all. The line drawing is only visual anyway.

So instead of having your turret create a laser beam object you could have it do a 'collision_line" check to see if it can hit the target and if so then draw your laser line and deal your damage to the player. If you need the line to last on screen for a bit just use an alarm that gets set when it shoots and as long as the alarm is going draw the line.
< >
Showing 1-6 of 6 comments
Per page: 1530 50

Date Posted: Oct 31, 2016 @ 10:19am
Posts: 6