GML Top Down Headshots || How Would it Work?

Gamerev147

Member
Hello!

I'm having trouble thinking of a way you can have headshots in a top down game.
If I have a sprite and the collision with the bullet, how could I make headshots?

Any ideas are appreciated. If anyone needs more explanation, I can give you some.
Thanks!
 

Cpaz

Member
The only way I think that could work is if you either to one of two things:
1: replace head shots with crits, and label them as head shots.
2: Have a tiny collision box (say 3-5 pixels wide) across the front of the sprite, rather than focusing on blindly shooting, you could focus on trying to center your fire.

Aside from that, I can't think of another way of handling it. It's definitely and odd situation.
 
R

R34LD34L

Guest
How would you even lol, ummm if !(irandom(10)) { headshot = true; }

Edit: You could check a region like a small rectangular bounding box above the head maybe.
 

Gamerev147

Member
The only way I think that could work is if you either to one of two things:
1: replace head shots with crits, and label them as head shots.
2: Have a tiny collision box (say 3-5 pixels wide) across the front of the sprite, rather than focusing on blindly shooting, you could focus on trying to center your fire.

Aside from that, I can't think of another way of handling it. It's definitely and odd situation.
I'll try this! I haven't thought of this.
Thank you so much!
 

KurtBlissZ

Member
Do extra damage if you click on the head if point_distance(mouse_x,mouse_y,x,y)<16

Or maybe something like this... idk.
Code:
var shot_dir = point_direction(xstart, ystart, x, y);
var target_dir = point_direction(xstart, ystart, enemy_x, enemy_y);
if angle_difference(shot_dir, target_dir) < 15) headshot=true;
Edit: You can maybe try using the collision functions too..Maybe just a circle or rectangle in the middle.
 
Last edited:

Niels

Member
you could implent it as a skill:

for example when you want to make headshot you have to keep a (sec?)fire button pressed for a amount of time while aiming at a enemy and when you release the button it triggers a headshot.

or a V.A.T.S system like in fallout :)


or something that would be quite a lot of work, but totally awesome (I think):

when you keep your special headshot/snipe button pressed while aiming at a enemy, it will pop up a small window with a silhouet that represents the enemy (in sideview) and a crosshair that represents your aiming.
Paint example I post below:

HEADSHOT.png

The crosshair will bounce around in the box and you have to let go of the button at the moment the crosshair is on the head to score a headshot else it will miss/hit the body.
 
J

Jacob T Wharton

Guest
Some Top Down Shooters have character sprites with shoulders, arms, and legs, instead of just a big floating head like in some other games.

If your character model includes shoulders, you could implement code that checks if you hit the "head" or the center of the model, otherwise do normal damage. Of course, most hits will be headshots if you do it this way.

I like the idea of having to hit your target "dead on," like hitting the 1-5 pixels in the exact center of the sprite. That keeps the gameplay fast and focused while adding an extra layer of tactics that encourages a choice: keep firing quickly and with low accuracy, or slow and time your shots to make each one count by maximizing headshots and thus, damage.

In my own TDS's, the best results came from random critical hits which are more likely to happen with certain weapons. If you add a nice, juicy particle effect on the enemy when you do a critical hit, it makes hitting the enemy very satisfying.

Whatever you decide to do, you have to keep in mind:

-is this making the game more fun?

That's pretty much all that's important in the end.
 

Gamerev147

Member
you could implent it as a skill:

for example when you want to make headshot you have to keep a (sec?)fire button pressed for a amount of time while aiming at a enemy and when you release the button it triggers a headshot.

or a V.A.T.S system like in fallout :)


or something that would be quite a lot of work, but totally awesome (I think):

when you keep your special headshot/snipe button pressed while aiming at a enemy, it will pop up a small window with a silhouet that represents the enemy (in sideview) and a crosshair that represents your aiming.
Paint example I post below:

View attachment 7023

The crosshair will bounce around in the box and you have to let go of the button at the moment the crosshair is on the head to score a headshot else it will miss/hit the body.
This is quite an amazing idea. I think I might try something like this.
Probably not the side view, but I have an idea!
 

lolslayer

Member
2 collision boxes, one for the head, one for the body, check first for the head and if you don't hit it check if you hit the body
 

Gamerev147

Member
I have an idea. But i'm going to need some help with it:
  • How can I make the camera zoom in on a certain object when holding a button?
  • How can I achieve "scope sway" in a top down game? For example, when you hold down the "snipe" button, your mouse starts to sway around automatically.
Thanks in advance, and thank you everyone who has replied; all very helpful ideas! :)
 

gmx0

Member
I have an idea. But i'm going to need some help with it:
  • How can I make the camera zoom in on a certain object when holding a button?
  • How can I achieve "scope sway" in a top down game? For example, when you hold down the "snipe" button, your mouse starts to sway around automatically.
Thanks in advance, and thank you everyone who has replied; all very helpful ideas! :)
Use the view_xview, view_yview, view_wview, view_hview variables.

Roughly (this is the most simple code just to give you an idea):
to sway (put in mouse button event)
view_xview[0]=mouse_x-(view_wview[0]/2);
view_yview[0]=mouse_y-(view_hview[0]/2);

to zoom in (put it with the sway code)
if view_wview[0]>320 //(replace 320 with a zoom level you want, lower number means closer zoom)
{
view_wview[0]-=1;
view_hview[0]-=1; //(replace 1 with zoom speed you want)
}​

to zoom out (put it in Step event)

if !mouse_check_button(mb_left) //(put mb_right for right click)
if view_wview[0]<1280 //(replace 1280 with the resolution/original view width)
{
view_wview[0]+=1;
view_hview[0]+=1; //(replace 1 with zoom speed you want)
}
The code probably will need to be changed for scaling, but it should work at its simplest form.
 

Gamerev147

Member
Use the view_xview, view_yview, view_wview, view_hview variables.

Roughly (this is the most simple code just to give you an idea):
to sway (put in mouse button event)
view_xview[0]=mouse_x-(view_wview[0]/2);
view_yview[0]=mouse_y-(view_hview[0]/2);

to zoom in (put it with the sway code)
if view_wview[0]>320 //(replace 320 with a zoom level you want, lower number means closer zoom)
{
view_wview[0]-=1;
view_hview[0]-=1; //(replace 1 with zoom speed you want)
}​

to zoom out (put it in Step event)

if !mouse_check_button(mb_left) //(put mb_right for right click)
if view_wview[0]<1280 //(replace 1280 with the resolution/original view width)
{
view_wview[0]+=1;
view_hview[0]+=1; //(replace 1 with zoom speed you want)
}
The code probably will need to be changed for scaling, but it should work at its simplest form.
How could I get the view to zoom in on an object other than the player?
 
J

Jacob T Wharton

Guest
To do a "gun sway," you could add a variable to your direction which is always fluctuating based on the sin() function.

For example:

Create event:
gun_sway = 0
gun_sway_amount = 3 //how much you want the gun to sway from side to side. Higher numbers means more sway.
gun_sway_speed = .1 //how fast you want the gun to sway from side to side. Higher numbers equals more speed.

Step event:
gun_sway +=gun_sway_speed
direction = point_direction(x,y,mouse_x,mouse_y) + sin(gun_sway)*gun_sway_amount


Play around with the variables to adjust the amount of gun sway. You could make the gun only sway in certain circumstances by setting the gun_sway to 0 before calculating direction, or by changing the gun_sway_amount:

if aiming_down_sights = true
gun_sway = 0


I am not at a computer right now so I do not know if this will work. Play around and see.
 
Top