Download the GMX for this tutorial:

I just released a new game!

Episode 6: Enemies
Difficulty: Beginner/Intermediate (GML Only)
A tutorial explaining the concepts of making shootable ‘enemies’ and making them interact with projectiles in GameMaker: Studio. 1080p is reccomended to help read menu items!

Read my blog!
Follow my twitters!

Intro clip animation by Hassan Otsmane Elhaou –
Intro music by Matthew Harrington –

Nguồn: https://shaarique.com/

Xem thêm bài viết khác: https://shaarique.com/game/

39 Comments

Danger the Penguin

July 2, 2020

Dose this also work in gms2?

Reply

Object Ash

July 2, 2020

Hi Shaun, which video comes after this one? Or was this the ned of this particular tutorial run?

Reply

Basil Constantinou Malek

July 2, 2020

put a copy paste for ur codes in desc

Reply

Corny Caleb

July 2, 2020

Your tutorials are so helpful. You explain how it all works and what it all does. Keep up the great work bro!

Reply

Sheng Plays

July 2, 2020

_________________________________________
FATAL ERROR in
action number 1
of Step Event0
for object obj_candycane2:

############################################################################################
VMError!! Occurred – Push :: Execution Error – Variable Get 100010.hp(100007, 0)
at gml_Object_obj_candycane2_Step_0 (line 7) – hit.hp -= 1;
############################################################################################
Self Variables :
hit(100006) = 100010

Reply

Imjeax Lundrack

July 2, 2020

I don't know when you added the step even to the bullet, but that image_angle = direction; is not working for me. The projectiles spawn sideways instead of slightly tilted

Reply

Daniel Pavlov

July 2, 2020

How to add a draw event to that instance. I have a draw event on my enemy which is triggered when a variable is changed by the "hit" but the draw event draws all enemies

Reply

_Bloodberry999_ & _Swagberry999_

July 2, 2020

help, i have an error:
_________________________________________
FATAL ERROR in
action number 1
of Step Event
for object obj_bullet:

COMPILATION ERROR in code action
Error in code at line 7:
}
^
at position 2: Assignment operator expected.

Reply

rajesh kumar

July 2, 2020

you are awesome

Reply

Corruption Gaming

July 2, 2020

ive been trying to make an enemy generator thingy but it would only spawn in a giant line of the enemies once. What I want it to do is spawn the enemies in randomly per generator throughout the game. can someone hel me with that?

Reply

DarkBoyDash

July 2, 2020

I….

Subscribed.
Very very great tutorial now i can make my own game thank you

Reply

mohanna1981

July 2, 2020

did he complete this game because the next videos he started teaching us other concepts using other games?

Reply

maxdax55

July 2, 2020

you saved my life!… MY FUCKING LIFE!!!

Reply

yes

July 2, 2020

so wait…why did he have to put "hit.hp" and not just hp? if you just put hp, wont you basically be saying that if it hits the enemy it will take away the health? whats the hit. for?

Reply

ButtonWalls

July 2, 2020

I set hp to 4 but it still dies in 1 hit, help.

Reply

Ángel García

July 2, 2020

People arr just bad on choosing a You Tube name, worst on photos :]

Reply

Ángel García

July 2, 2020

Hey Shawn, can U do a rougelike tutorial? just asking, is kinda famous :]

Reply

Benny Yum

July 2, 2020

what if i want to used the event collision, how do i do that?

Reply

guy3480

July 2, 2020

I tried to make it so that multiple enemy types take damage from the bullet but now the collisions dont work

hit = instance_place(x,y,obj_enemy);
hit = instance_place(x,y,obj_enemy_2);

if (hit != noone)
{
hit.hp -=1;
instance_destroy();
}

any reason why this doesnt work?

Reply

TheBlueEngineer

July 2, 2020

I find the way you made the enemy take damage when colliding with the bullet ineffective and it honestly isn't very easy to make the bullet do damage to other enemies. A more simple and effective way to do this is to make a collision event with the enemy, and make it so the enemy takes damage, then the bullet is destroyed. Then, just copy that event for other enemies!

Reply

SuperStarOfLife

July 2, 2020

Do I need to use vspeed because my game is sorta like the legend of Zelda you know that movement

Reply

Harbinger

July 2, 2020

How do you make the faces shoot at you?

Reply

Linkdeous

July 2, 2020

It's really weird, i have a problem, can someone help me ?

I have set the Alarm1 to 4, to make an alarm for ennemy shot, but … i put this in the step event but it doesn't seem to set my Alarm1 to 4 :/

if (alarm[1] = -1) alarm = 4 ;

In the alarm1 event, i just wrote the basic : instance_create(x,y,obj_bullet); :/
Can someone help me please ?

Reply

Seth Minturn

July 2, 2020

Hopefully someone can answer this for me, but when I am shooting my projectiles (fireballs in this case) they all disappear when they hit the enemy. They don't keep streaming out like Shaun's blue lasers, they all disappear when they come in contact with the enemy object….

Reply

Kaltagg

July 2, 2020

What if you have two types of bullets, with different damage? It will always read the first bit of code first, and always do that damage, because of using noone. How do you fix this?

Reply

Ad0ns

July 2, 2020

Shaun it isnt it far more simple to declare a variable : HP and assign it the value 5. THen in a step event we can check:
if(HP){

}else{

destroy_instance();

}

Example: if the HP is 5 and you take a hit then destroy the bullet and HP -= 1.Simple.. When the HP var will hit 0 or lower it will destroy the object..

My solution is far more simpler for everybody.. (I know programming) Btw creating a clone of that object is useless.

Reply

StuffandThings85

July 2, 2020

I'm making a boss, and I want his behavior to change based on his HP. For example: he starts with 5HP, and uses mild attacks, at 4HP he gets slightly faster and more aggressive, and at 2HP gets even more aggressive. I can set alarms to time his attacks a certain way, but I only want it to get more aggressive when health gets lower. Is there a way to set a variable to call an alarm sequence? I tried 'alarm_get()' but that didn't affect the boss behavior at all, just stayed mild.

Reply

Av8r Gamez

July 2, 2020

Great video!

Reply

Dominik Konečný

July 2, 2020

Guys, could someone help me ? I can't find the "hit" script in his videos and it says "unknown function or script: hit" can someone help me ?

Reply

Kato Kik Alhaalta

July 2, 2020

+Shaun Spalding Why ? 😮
_________________________________________
############################################################################################
FATAL ERROR in
action number 1
of  Step Event0
for object obj_testenemy:Variable obj_testenemy.hp(100003, -2147483648) not set before reading it.
 at gml_Object_obj_testenemy_StepNormalEvent_1 (line 1) – if (hp == 0) instance_destroy();
############################################################################################

Reply

bop

July 2, 2020

Awesome! thank you so much!

Reply

Mister Dee

July 2, 2020

when u type instance_destroy();
what could be inside the bracket?

Reply

Rafael Sannin

July 2, 2020

Guys, I did everything right, but… I have a little problem that I can't find solution.

My ship fires properly.
The shots take the hp of the enemy.
The enemy is destroyed along with the shoots.

But when the enemies are closer to my ship, stop taking the hit. The shots cross for them, as if were no object there.

(sorry my english)

Reply

Ciara Janay

July 2, 2020

I literally just sat for hours trying to figure this out and you helped me in like 4 minutes thanks you made it really easy to follow and were pretty thorough.

Reply

Nanof Urbiznis

July 2, 2020

At 7:09 what is hit.hp? I didn't understand why it's written that way. Why not just hp -= value ? What's the function of the dot here.

Reply

Hisyam Hanafi

July 2, 2020

what is (x,y,obj_enemy)? i didnt understant what x and y refers to

Reply

Hisyam Hanafi

July 2, 2020

when do u declare hp? because u create ur own var so u must declare it to something..

Reply

Pixzor

July 2, 2020

this happens
_________________________________________
############################################################################################
FATAL ERROR in
action number 1
of  Step Event0
for object obj_lazer:Variable obj_lazer.obj_enemy(100002, -2147483648) not set before reading it.
 at gml_Object_obj_lazer_StepNormalEvent_1 (line 3) – hit = instance_place(x,y,obj_enemy);
############################################################################################

Reply

Pixzor

July 2, 2020

this is what I have and it still wont work image_angle = direction;hit = instance_place(x,y,obj_enemy); if (hit != noone)
{
    hit.hp-=1;
    instance_destroy();}

Reply

Leave a Reply