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

GameMaker How to make enemy dead body face the player?

D

daddysucc5000

Guest
I'm new to game maker and I'm making a top-down shooter similar to Hotline Miami. Right now I have an enemy and a player and when the player shoots and the bullet collides with the enemy the object changes to the dead body object.
My problem is that the dead body sprite doesn't face the correct way where the bullet came from.
I want it to be like in Hotline Miami where the dead body faces where the bullet came from if that makes sense.
My dead body object is called oDeath and my enemy object is called oEnemy
Sorry for bad English.

My code right now is:

Enemy collsion event with bullet:
Code:
instance_destroy();
instance_create_layer(x,y,"Dead",oDeath);
instance_create_layer(x,y,"Blood",oBlood);
instance_create_layer(x,y+25,"Blood",oBlood2);
Create Event in oDeath
Code:
direction = (-oPlayer.image_angle);
image_angle = direction;
 

BenRK

Member
Try using point_direction(x1,y1,x2,y2). That might fix the issue.

I may have misunderstood what you were asking. Am I right in assuming that the dead body faces the player and not in the direction it would look like had it fallen over backwards?
 
Last edited:
D

daddysucc5000

Guest
Try using point_direction(x1,y1,x2,y2). That might fix the issue.

I may have misunderstood what you were asking. Am I right in assuming that the dead body faces the player and not in the direction it would look like had it fallen over backwards?
I think you are right. I want it to be exactly like in Hotline Miami when the enemy's get shot. So the feet always face where the bullet came from. I'm also not really sure how i should use point direction like you suggested.
 

BenRK

Member
Don't worry about it. What you're doing is having it fall away from the direction the player is looking, and the player has likely moved and looked elsewhere since then. What I'd do in this case is use the bullets direction instead of the player. You can do this in the collision event when you make the dead body object.

I'd do it like so:
GML:
var inst = instance_create_layer(x,y,"Dead",oDeath);
inst.image_angle = other.direction+180;
Then just take out the code from the dead body create event.

instance_create_layer and the other instance_create function returns the object ID of the instance created, so you can use this to pass variables to it right away. the other in this case only works in the collision event, and it is the ID of the object that collided with it, in this case it should be the bullet object.
 
D

daddysucc5000

Guest
Don't worry about it. What you're doing is having it fall away from the direction the player is looking, and the player has likely moved and looked elsewhere since then. What I'd do in this case is use the bullets direction instead of the player. You can do this in the collision event when you make the dead body object.

I'd do it like so:
GML:
var inst = instance_create_layer(x,y,"Dead",oDeath);
inst.image_angle = other.direction+180;
Then just take out the code from the dead body create event.

instance_create_layer and the other instance_create function returns the object ID of the instance created, so you can use this to pass variables to it right away. the other in this case only works in the collision event, and it is the ID of the object that collided with it, in this case it should be the bullet object.
This worked! Thank you so much I was stuck on this for 3 days. And thank you for responding very quickly.
 
Top