I
IzzieBlu
Guest
Hello all I have a bit of a problem and I need a some help with it. I'll explain as well as I can.
I'm currently working on a top-down shooter for fun where you can at shoot enemies over furniture and non-solid objects but not through walls and solid objects. In the game when you click (shoot) it creates an instance of the shot object and any enemy object touching that will check if there are any solid objects in between the player and itself. Only problem is that I'm not entirely sure how to do that.
While trying to get this to work I fiddled around with the collision_line() function, but to no avail; the collision_line() function doesn't work how I thought it would (check if there are any solid objects colliding with the line between the two objects or points).
(red = collision/can't damage, green = passes through/can damage)
With this code the enemy is damaged no matter what is in the way, even if theres nothing. I have tried all combinations and it only ever resulted in either the enemy always being damaged or the enemy never being damaged (removing the '!', changing the condition to .solid, changing the contition to == noone, etc.).
I've looked all over the place online and I can't seem to find any posts, tutorials or anything useful or very relevant to my problem.
If you have any ideas that would be very helpful and appreciated!
(sorry if I called something incorrect or used wrong terms; I'm self taught)
Thank you for reading~
If so: is there a way to only draw the shot up to that point? (Currently the shot is simply an image however I've been thinking of changing it to a generated line of sorts)
Since both of these are not entirely needed for the core of the game I don't need them answered; these two questions are simply similar so I added them is as well.
I'm currently working on a top-down shooter for fun where you can at shoot enemies over furniture and non-solid objects but not through walls and solid objects. In the game when you click (shoot) it creates an instance of the shot object and any enemy object touching that will check if there are any solid objects in between the player and itself. Only problem is that I'm not entirely sure how to do that.
While trying to get this to work I fiddled around with the collision_line() function, but to no avail; the collision_line() function doesn't work how I thought it would (check if there are any solid objects colliding with the line between the two objects or points).
Heres the code I'm working with:
Code:
if(!object_get_solid(collision_line(x, y, obj_player.x, obj_player.y, obj_zombie, 0, 0)) && place_meeting(x, y, obj_shot))
{
hp-=obj_shot.dmg
with(obj_shot){ instance_destroy() }
}
(red = collision/can't damage, green = passes through/can damage)
With this code the enemy is damaged no matter what is in the way, even if theres nothing. I have tried all combinations and it only ever resulted in either the enemy always being damaged or the enemy never being damaged (removing the '!', changing the condition to .solid, changing the contition to == noone, etc.).
I've looked all over the place online and I can't seem to find any posts, tutorials or anything useful or very relevant to my problem.
If you have any ideas that would be very helpful and appreciated!
(sorry if I called something incorrect or used wrong terms; I'm self taught)
Thank you for reading~
Bonus / Extra:
As well as that, I was wondering if there would be a way to not allow an enemy behind an enemy to get shot/damaged by the shot.If so: is there a way to only draw the shot up to that point? (Currently the shot is simply an image however I've been thinking of changing it to a generated line of sorts)
Since both of these are not entirely needed for the core of the game I don't need them answered; these two questions are simply similar so I added them is as well.