GameMaker Studio 2: Melee Attacks Tutorial

  Рет қаралды 192,018

Shaun Spalding

Shaun Spalding

5 жыл бұрын

▶ Source code: shaunjs.itch.io/shauns-melee-...
▶ Part 2 - Combo Chains! • GameMaker Studio 2: Me...
▶ Support my work: / shaunjs
A remade, revamped and more in depth video on melee attacks for GameMaker Studio 2. Part 1 covers a basic attack using a state machine, part 2 will cover combo chains.
Shout outs to PixellatedPope and other members of the GameMaker subreddit discord channel for their help in making this video.
▶ Animation_end() script: pastebin.com/0AsJn1WB
▶ State machines in depth: • GameMaker: State Machi...
▶ GameMaker Discord: / rgamemaker_discord_ser...

Пікірлер: 429
@ShaunJS
@ShaunJS 3 жыл бұрын
Over the years many people have suggested that this code will cause your player to be "invincible" for a frame because of swapping the collision mask. This is not true. You're not invincible as the code runs sequentially. You swap masks and then you swap back after the check is complete. An enemy will only ever perform its own check before or after this, not during. So it is not in any sense invincible at any point. Even if we forgot to swap it back, you would actually just gain the collision mask of the attack and you still wouldn't be invincible. Though it would be undesirable! Nontheless, as long as you swap your collision mask back after finishing your check, there is no problem at all.
@yungefendi6480
@yungefendi6480 3 жыл бұрын
Hey Shaun, I would really appreciate if you would do an "updated" tutorial for this, since scripts have changed and many people including me, on the forums don't know how to set up these types of states with the new changes
@ShaunJS
@ShaunJS 3 жыл бұрын
@@yungefendi6480 you do exactly the same thing just put each script into a function. I made a video on these changes a little while back.
@ShaunJS
@ShaunJS 3 жыл бұрын
(I do however, plan to update most of these videos eventually)
@yungefendi6480
@yungefendi6480 3 жыл бұрын
@@ShaunJS ive just seen it. my code: state = walker_patrol(accspd, maxhspd) script_execute(state); i get error „script_execute argument 1 incorrect type (undefined)“ the two arguments are defined in the function walker_patrol so any idea whats wrong?
@ShaunJS
@ShaunJS 3 жыл бұрын
@@yungefendi6480 by supplying arguments you're calling the script, not assigning it to the variable. You assign a function to a variable by writing its name without the brackets.
@MasterAlbert
@MasterAlbert 5 жыл бұрын
Because of you I have released my first game and it got 200 downloads on the first day. I owe all I know in GM to you, thanks so much
@SketchyScribe
@SketchyScribe 5 жыл бұрын
Aljon D. Do you mind if I get a link to the game I'd love to check it out!
@Boreality_
@Boreality_ 5 жыл бұрын
Seconded, I'm really curious how it is!
@arxci9402
@arxci9402 5 жыл бұрын
Yeah. Link? Please
@Tneeder
@Tneeder 5 жыл бұрын
If its the one on your youtube page i gotta say it looks pretty nice, well done!
@MasterAlbert
@MasterAlbert 5 жыл бұрын
@@Tneeder that's the one. soul chase is the name. thanks! glad you liked the trailer!
@Khiast
@Khiast 5 жыл бұрын
WOW.. I was just trying to figure out how to code melee attacks in GM Studio (I'm very new to GML) and I have been watching your tutorials, and now you post this video, thanks so much for great tutorials! Wish you the best!!
@inkanonymous3064
@inkanonymous3064 4 жыл бұрын
This is literally exactly what I needed, and I wasn't even looking for this! Thank you!
@autumnshade84
@autumnshade84 5 жыл бұрын
Thanks Shaun again for building a bridge for us new to GMS to learn the ropes and build our ideas into reality. Thanks also for giving credit where its due, it creates a great example to follow.
@STARmod
@STARmod 5 жыл бұрын
WAS NEEDING THIS TUTORIAL SO BAD! Thanks Shaun!
@ShaunJS
@ShaunJS 5 жыл бұрын
Part 2 out next Friday! (or now for $5 patrons!) Here is the animation_end() script that was used: pastebin.com/0AsJn1WB
@Kakite7319
@Kakite7319 2 жыл бұрын
not working plz update
@fattcoke4705
@fattcoke4705 2 жыл бұрын
I was amazed when the code in this tutorial worked after only 1 bug fix. That's a first for any piece of code from any tutorial. Absolutely amazing tutorial.
@oldgamernewworld5045
@oldgamernewworld5045 3 жыл бұрын
Thank you so much Shaun Spalding for all of your tutorials you have been a big help for me so much with because of you I too was able to release my first game SA4A and soon another title thanks to you. Thank you for all that you have done. Have been and will be supporting you all the way.
@Zokuin
@Zokuin 2 жыл бұрын
Great video tutorial Shaun! Clear, simple and that animation_end code is truly a life saver. Just a heads up for everyone: If you want to make your player attack while airborne add image_speed = 1; under image_index = 0; in the attack state script. Somethin like this: //start of attack if (sprite_index != player_attack_animation) { sprite_index = player_attack_animation; image_index = 0; image_speed = 1; } That way your player won't act crazy when you attack in the air and probably you don't want to set your horizontal and vertical speed to 0 for it to work. Also make sure that in every animation the upper right option is set the same. If you don't your player will teleport when you attack. Hope it helps anyone with the same issue!
@user-nn9mg3sw9j
@user-nn9mg3sw9j 7 ай бұрын
Thanks for this tip; was wondering how to stop my char from freezing in the air. Now I'm on to trying to figure out how to keep my momentum through the attach animation. I've even put the move code in the attack state, but regardless every time I attack my horizontal speed is zeroed for that fraction of time. If I click attack a lot it's very clear that my character stops current movement to perform the attack. But I want my character to show attack animation while still moving in the current direction. Quite frustrating.
@germanmetroid
@germanmetroid 3 ай бұрын
Hey there, just wanted to thank you so much for this tutorial! In fact, your platformer tutorial series was a basis and amazing startup for my GML journey, and so far It's been an experience, from just "Hope this works" to "This will work so good" mindset Was looking for a framework for melee attacks and saw your's and implemented it to my game and it works perfectly. Hope you are well and looking foward for more videos in general in the future!
@ReedNunnemaker
@ReedNunnemaker 3 ай бұрын
I'm getting a "Compile Scripts...Error : duplicate script name found gml_Script_Playerstate_attack_hit" whenever I try to run my game. Did you get this? and how did you fix it
@thecclicker
@thecclicker Ай бұрын
I'm very skeptical because this video is old and it will not work, so I'm just watching for the theory
@joshaklese4969
@joshaklese4969 5 жыл бұрын
Thanks for all you do. A video showing the set up process and everything start to finish would be helpful. I say this because your tuts matter.
@Overworld_FN
@Overworld_FN Жыл бұрын
Part 2 out next Friday! (or now for $5 patrons!) Here is the animation_end() script that was used: pastebin.com/0AsJn1WB copied)
@chestnut45
@chestnut45 5 жыл бұрын
Hell yeah! Can't wait for part 2 :) great tutorial
@LanceCS
@LanceCS 3 жыл бұрын
This tutorial works perfectly! It helped me a TON. Thank you!
@almog0114
@almog0114 5 жыл бұрын
so far i always just used the collision box collision event with enemy to do melee damage , is there any benefit using this method over just collision event ?
@toniconge7003
@toniconge7003 5 жыл бұрын
Thank you very much! Think I got a good understanding of how states work thanks to this.
@Satorl
@Satorl 8 ай бұрын
damn, ive been using extensively the image_index > image_number-1 thing for over a week now on a project BECOUSE of the manual and now by chance i see what you just said there, and that explains quite a few things now haha thanks for that
@CoTn
@CoTn 5 жыл бұрын
AWESOME ! I was waiting for this.
@pubblesss
@pubblesss 5 жыл бұрын
Thanks again, Shaun. You are the best!
@Tonbeans
@Tonbeans 2 ай бұрын
6 yrs later... Thank you Shaun. I hope you keep up with the videos, you are too important for the Game Maker Community
@nitneat
@nitneat 5 жыл бұрын
I was searching this today,looking at your other melee tutorial
@GT-fresh
@GT-fresh Жыл бұрын
Shaun! Can you tell me, you didn't show the codes in the folders: AnemyStage_free,dead,hit! in which video did you write it? Thanks!
@boytriesstuff
@boytriesstuff 4 жыл бұрын
hey there im facing problems with gms 2 it's whenever i press the Q button to attack i turn into a wall and i dont know what to do please help me
@ctobi707
@ctobi707 4 жыл бұрын
i see you didn't use delta time when you added hspeed to x. is this something specific to gamemaker studio? or am I missing something about frame rates. thank you
@dopamine7344
@dopamine7344 Жыл бұрын
if anyones getting stuck in the air and only playing the first frame of the attack remember to make your image speed 1, in some tutorials (like shauns platforming one) they have you make your image_speed 0 so when you attack in the air your image_speed stays at 0 so you do no animations nor do you progress to the part where the hitboxes come out in your animation. :)!
@greeniecapvideos8674
@greeniecapvideos8674 Жыл бұрын
I’m having trouble running the game. When I copied the player’s code from line 4 and paste it into the script, PlayerState_Free, an error message comes up when I run it, showing that the error is from Line 1 of the script. Is there anything I’m doing wrong?
@DelphineEraklea
@DelphineEraklea Жыл бұрын
please google it, as now all scripts require to be surrounded by function your_function_name() {} if you want them to function
@Jake-zu2xx
@Jake-zu2xx 3 жыл бұрын
Hey man i know im a bit late but im doing my first game and your guide is being SO helpfull by now. I was wondering where to find the combo slash tutorial since i cant find in your vids (im blind) Good work and thanks!
@floofimations2643
@floofimations2643 5 жыл бұрын
can you please make a video showing the enemystate code? i cant figure it out and im having major issues with it
@amygdalagames5950
@amygdalagames5950 4 жыл бұрын
solved it?
@maul8456
@maul8456 4 жыл бұрын
I have the same question my friend
@mushroomdude123
@mushroomdude123 3 жыл бұрын
@@maul8456 His Gamemaker 1.4 tutorial on melee attacks has the code you're looking for.
@wingboy0
@wingboy0 5 жыл бұрын
i was looking forward to this
@ghb323
@ghb323 5 жыл бұрын
The hit list is a really good idea than to use “invincibility frames”, as it just merely slows the hit frequency and just acts as a damage cooldown before the enemy becomes vulnerable again.
@elbituan
@elbituan 4 жыл бұрын
Hello friend, can you please help me with the automatic subtitles of this video? Do you remember ?, it is only deactivate and activate, without deleting. Thank you.
@elbituan
@elbituan 4 жыл бұрын
Please Shaun :( I need this video jejejejee, Cheers
@alric_
@alric_ 5 жыл бұрын
That took more time than i expected it.
@pigdude3068
@pigdude3068 4 жыл бұрын
When you make the horizontal and vertical speed equal to 0 upon entering the slash player state, is that entirely necessary? It seems like it would allow for people to just spam the attack button and hover in midair, and I don’t see any consequences for not implementing it.
@blockcabin
@blockcabin 4 жыл бұрын
this might seem super simple, but i want to know, if i have more than one enemy, how do i reference it? you just put oEnemy in your hits variable, but what if you have multiple types? the parent enemy does work. i would really appreciate an answer
@Karak-_-
@Karak-_- 4 жыл бұрын
Well it depends on what you mean "more then one enemy". Asuming you mean multiple enemy _objects_ (oArcher,oKnight,oMage...) creating a parent object oEnemy and making it parent of all enemies, then using oEnemy in colisions should work.
@Karak-_-
@Karak-_- 3 жыл бұрын
@@gphi6053 It don't have to. It can be an "empty" object whose only purpose is to be a parrent.
@dominus2366
@dominus2366 5 жыл бұрын
Awesome tutorial! Looking forward to seeing more videos like these. By the way, I would really love it if you made a tutorial on a dash mechanic, I really need help on that and there really isn't any new tutorials about this, at least I couldn't find any GMS2 dash tutorials, so that would be pretty cool.
@zuzu2971
@zuzu2971 2 жыл бұрын
its easy. get the sign from hsp and then if ur pressing a key just increase the hsp
@sleepymatth6025
@sleepymatth6025 2 жыл бұрын
after that, it needs to set hsp to the previous value , but out of the if statement, because if you don't, the hsp will always be equal to the value it returns if you press the key
@OdinGamingMC
@OdinGamingMC 5 жыл бұрын
I have recently started to code with game maker and I am watching your complete plat former series and I find when I try to make a stripe for my walking animation, It doesn't come up with 7 different images, it comes up with one long image, when I try to Import all of the images one by one, I can only import 1 or else it will delete the rest. Sorry if this is a easy fix or if I'm using a outdated series but if you know can you please tell me, thanks.
@PixelatedPope
@PixelatedPope 5 жыл бұрын
Did you name the sprite properly? It needs to end with "_strip7.png" or whatever your extension is. It's a sprite "strip" not a "stripe". Alternatively, you can create a new, empty sprite. Selected edit to open it in the sprite editor, and then at the top select image>import strip image (ctrl+i) That will bring up a new window to help you define your sprite strip similar to defining a tileset. Hopefully that helps.
@OdinGamingMC
@OdinGamingMC 5 жыл бұрын
thank you for the help, it worked!
@ethancates7779
@ethancates7779 3 жыл бұрын
to anyone getting stuck in the air on the first image when they try to attack: change where it says "image_index = 0; to image_speed = 1; it worked for me
@n0cturnalSFX
@n0cturnalSFX 2 жыл бұрын
thanks a lot that really helped me out lol :)
@Gameout50
@Gameout50 5 жыл бұрын
Listened to the opening and found out I already did this type of thing in the game I'm making, now gonna finish watching to compare the two. :3
@Codamations
@Codamations 5 жыл бұрын
ichimo I have a channel that does speedpaints, animation and coding and animation tutorials, and funny and storytelling animations please consider subscribing
@Gameout50
@Gameout50 5 жыл бұрын
@@Codamations No. :D
@kcazz2832
@kcazz2832 4 жыл бұрын
When I added this to my game the attack keeps triggering every frame, playing my attack sound multiple times and killing the enemies instantly.
@e4gyofficial
@e4gyofficial 5 жыл бұрын
strange, he chose an identical deltarune sprite this time
@ShaunJS
@ShaunJS 5 жыл бұрын
It's not identical! It's incredibly close because I just really liked that sprite (and I'm a bad artist who relies massively on reference). But I did all the swings myself! ...that counts right?
@e4gyofficial
@e4gyofficial 5 жыл бұрын
@@ShaunJS what really counts is having fun at your work
@Karak-_-
@Karak-_- 4 жыл бұрын
Same here, I am capable of modyfiing sprite to suit my needs but I always need a template. The most original thing I painted was sprite of Peanut with legs that goes up and down. And I did that on accident. In one of my projects I used sprites from The Escapeists as a template for both Player Character and Zombies, and to call them my own I have added idle animation and improved current walking animation. I probably reuse those sprites as a template since I have lost interest in that project. In my current project I have used Frisk, repainted it black/red/grey added three hand gestures and +- 10 facial expresions. And here is Magican The Great. SkelyHat, autor of said sprite, looks really fine with people using them as long as he/she gets credited.
@TheWaynelds
@TheWaynelds 3 жыл бұрын
@SrTreo I believe the correct term is “wooosh”, not “r/wooosh” There’s no reason to include “r/“. Besides, the guy you replied to doesn’t even deserve to be woooshed.
@SpringDavid
@SpringDavid 3 жыл бұрын
@SrTreo that wasn't very wholesome 100 from you.
@CrawlingShadow9
@CrawlingShadow9 5 жыл бұрын
Hello! I followed this tutorial and l am having a slight issue... My character attacks and animates properly, but only while I'm on the ground. If I try to attack while mid-air then it freezes on the first frame of the attack animation and he gets stuck in mid-air. I tried applying the physics code from the free state, but all that does is make him slowly descend while still frozen on the first frame. And then he's still stuck after hitting the ground. Am I doing something wrong? (Probably)
@vanthelow
@vanthelow 5 жыл бұрын
Did you fix the issue already, if so could you provide me with your fix. I'm having the same problem and all I could figure out is that it is probably caused by the animation_end() script.
@CrawlingShadow9
@CrawlingShadow9 5 жыл бұрын
@@vanthelow haven't got it figured out yet. I will let you know if I do. Although, I get the same effect even if I remove the animation end script from the equation.
@vanthelow
@vanthelow 5 жыл бұрын
@@CrawlingShadow9 yeah I noticed that too, it is weird because any other code i put in the script works fine, except this one. I'm actively working on the project and that bugfix so ill let you know too if we coms up with something.
@vanthelow
@vanthelow 5 жыл бұрын
@@CrawlingShadow9 Hey, I dont know if you have a solution yet, but changing image_index = 0; to image_speed = 1; worked for me.
@CrawlingShadow9
@CrawlingShadow9 5 жыл бұрын
Thank you much! I've been at work so much I haven't had time to work on my project. You are a life saver!
@amittens7473
@amittens7473 2 жыл бұрын
whats in the other scrips like the enemy free and state hit i dont think what youre showing can function without the codes in those scripts unless im getting something worng
@daigunsaga2631
@daigunsaga2631 3 жыл бұрын
sooo... how hard is it to impolement a state machine in your platformer video if im like 15 episodes in. its just i designed my character for melee and i thought that tutorial would cover it and now im trying to implement state machines and my player keeps getting stuck in mid air and things are just crumbling at my feet when i try to implement it. is it too late?
@andrewhawkins451
@andrewhawkins451 5 жыл бұрын
Can someone help me! For some reason, the function instance_place_list is not turning orange even though it is written the exact way it is shown in the video.
@sevoir2551
@sevoir2551 4 жыл бұрын
So I have two different sprites, one for moving and one forstill with a sword, how do I code it so that those sprites only show up when I hit the button Thanks!
@user-jc1ci5ub6s
@user-jc1ci5ub6s 5 жыл бұрын
im getting an error Script: PlayerState_Attack_Slash at line 13 : unknown function or script instance_place_list
@tekspurtzltd8238
@tekspurtzltd8238 5 жыл бұрын
var end_anim = image_index >= (last frame) if(!end_anim){ image_speed = 1; } else{ image_speed = 0; image_index = 0; change state..... } That's how I usually do animation end, but the script you posted is great!
@theternal
@theternal 5 жыл бұрын
You can use image_number-1 instead of writing the last frame manually.
@PixelatedPope
@PixelatedPope 5 жыл бұрын
Yeah, the biggest problem with this is that it's no longer accurate for GMS2, since your sprite can be in frames per second or in frames per step. Which is why the script is so much more complicated. That being said, if you know ALL of the sprites that will use the above code are set to frames per step, then yeah, that'll keep working.
@wilhelmgstudios8594
@wilhelmgstudios8594 3 жыл бұрын
hey Shaun! Quick question - I have a gamepad and all the face buttons, and the axis work fine, however the dPad doesn't work at all. I looked around and saw others had the same issue, but there was no solution. If there isn't a way to get them to work, is there a way to have the analog stick act as a 4-directional input? I'm trying to do an old-school style top down movement, and if the dpad doesn't work, that's the next best thing.
@mem3b0i_
@mem3b0i_ 2 жыл бұрын
You could use an ”or” statement Example (xDir = analog_Left; || xDir = Dpad_Left); Disclaimer, not sure if this actually works or not, and the code for the inputs are different from what they’re called in gamemaker. (Like wtf is dpad_left lmao)
@mem3b0i_
@mem3b0i_ 2 жыл бұрын
I’ve just noticed this was 9 months ago
@austincreates5034
@austincreates5034 5 жыл бұрын
Ive got a question, Ive followed the code correctly, but somehow, it does everything except for interacting with the object its supposed to be interacting with. it actually doesnt do anything. no hits, no destroying, not calling up the script, nothing at all. any ideas on how i can solve this??
@zayJax
@zayJax 5 жыл бұрын
did i miss a tutorial? cuz you don't explain the Enemy (except EnemyHit) scripts, the corpse, EVERYTHING except the player. i'm sorry for being so mean... should i duplicate the player's scripts and put enemy and call it a day?
@pupaproductions4784
@pupaproductions4784 5 жыл бұрын
watch the platformer series he covers shit about enemies :)
@zayJax
@zayJax 5 жыл бұрын
@@pupaproductions4784 i watched the whole series
@nijuatama4362
@nijuatama4362 4 жыл бұрын
soooo i followed everything and checked multiple times but my character if on ground just keeps playing the attack animation on loop, i can't move him nor jump , also if i run the game again and start by jumping then press the attack button he just stops mid air, does the attack animation once then fall and return to FREE state, i tried changing stuff but still didnt work
@gamedesignandps4play476
@gamedesignandps4play476 5 жыл бұрын
To check if you are on the last frame of the animation have you tried this? if image_index >= image_number - sprite_get_speed(sprite_index)/room_speed
@MongoGamer
@MongoGamer 5 жыл бұрын
so if im on GM studio 1 and i dont have the clean up event how would i handle destroying the list?
@lagork489
@lagork489 3 жыл бұрын
in which video do you configure the scripts of the enemies? :/
@kolymsky861
@kolymsky861 5 жыл бұрын
Always love your videos, have been very helpful to me over the past few years. Just wondering if you'd ever consider making an Oregon Trail type game? Trying to make my own currently and I'd love to see how you'd tackle it. Keep making awesome guides dude
@justinmoss5424
@justinmoss5424 Ай бұрын
If you are receiving an error re: Variable and the location is one of your scripts (such as PlayerState_Free), you may be missing the "function" line in your script (introduced in version 2.3.0). In each script, you need to add "function", then the name of the script [such as PlayerState_Free()], then place the contents of the entire script in curly brackets. Ex. PlayerState_Free script should be: function PlayerState_Free() { **the contents of your script/the script from the video go here** } When you create a new script, GMS will actually present this format automatically, and will have notes that the script assets changed for v2.3.0. Hope this helps!
@Koffsyrup
@Koffsyrup Ай бұрын
my brother... thank you so much!
@GuerraLollo
@GuerraLollo 3 жыл бұрын
At 15:34 you said that there's a method faster and better than collision precise per frame. Could I ask you a tutorial over that method? I really like your videos, thanks you.
@fuckyougoogle5899
@fuckyougoogle5899 4 жыл бұрын
Hey Shaun! Thank you so much for this video it's super informative! I just have one question, Because you are swapping the collision mask from your sprite to your weapon, is it possible that you could run into problems with the wall collision checks? For example walking through walls because your hitbox is not more to the right or something like that? Thanks!!
@ShaunJS
@ShaunJS 3 жыл бұрын
No. Because it is swapped back after the check is done.
@PrimitiveAspid
@PrimitiveAspid 2 жыл бұрын
I swear, officer, I didn’t see “Fuck you, Shaun.”
@CarGuyCole360
@CarGuyCole360 3 жыл бұрын
ATTENTION: If you're using the latest version of gms2, there should be one extra line of code at the top of the scripts, and curly braces after said line of code and finish after the entire script.
@maitreyiramkumar7219
@maitreyiramkumar7219 2 жыл бұрын
What is the line of code
@fatmen7391
@fatmen7391 2 жыл бұрын
@@maitreyiramkumar7219 function i think
@jdoe27
@jdoe27 2 жыл бұрын
something like function name { the script } i think
@nathanlawrence656
@nathanlawrence656 2 жыл бұрын
I NEED HELP! I've been following Shaun's Complete Platformer Tutorial playlist, but I wanted to add melee attacks instead of guns and shooting. So I ended up here, trying to incorporate this into my project. I added the function "script name" with curly braces covering the entire script from my previous tutorial's work's coding for movement, pretty much as Shaun has done in this video. But since I've added this "ATTACK" script and "FREE" script, I can no longer move (or punch). We've called scripts in his platformer tutorial before and I did it the same way. I don't get any errors when running the game, I just can't move or attack with my character, he remains in idle.
@jdoe27
@jdoe27 2 жыл бұрын
@@nathanlawrence656 I´m not sure. Did you move the part of the code where you calculate horizontal and vertical movement to the script with the attack state? Because then you´ll only be able to move while in that state, so you want to keep all that stuff in the normal step event for the player
@alex01763
@alex01763 5 жыл бұрын
What is the difference between using lists and just checking collision and adding events to the enemy object?
@malejtonda
@malejtonda 5 жыл бұрын
Hi Shaun. This was a great video. I have one problem with my first game. Its when I touch a wall, my game laged. I make a code that will restart the game (I copy that from your another video). The code worked. But it doesn't worked when I touched the wall. So my question is "Can my laptop run the game or it is by something else? (my game have codes of movement, collisions and variables)". P.S. sorry for my english.
@GatorFreak100
@GatorFreak100 5 жыл бұрын
I'm currently stuck on making the enemy take damage. I'm not really sure how to set up an enemy script because you didn't show them too much. I'm trying to figure out how to do it (either with scripts or alternative methods), but I can't find anything online and I don't know how to do any of this. Everything I try with my limited knowledge just does not work.
@pupaproductions4784
@pupaproductions4784 5 жыл бұрын
instead of calling the enemy damage script under "with (hitID)" put instance_destroy(); that should ANIHALATE the instance id of your enemy being effected in your for loop :)
@KafanskaTV
@KafanskaTV 5 жыл бұрын
Go back to earlier platforming tutorial video where he deals with creating and damaging/killing enemies.
@jackssparrow1232
@jackssparrow1232 Жыл бұрын
does this still work for top-down games? I am looking to implement a melee combat mechanic to my top-down shooter game for some variation and was wondering if this would still work
@Zirofol
@Zirofol 3 жыл бұрын
I followed the tutorial but when I press the attack key my character dissapears instead of doing the attack animation (except if I'm in the air when I press attack, then it works).
@megamanlyharkinian1373
@megamanlyharkinian1373 2 жыл бұрын
hey shaun, huge fan of the work you do. i'm just wondering, how would i use the collision checking code for different enemy types? with "var hits = instance_place_list(x,y,obj_enemy,hitbyattacknow,false);", the code seems like itd only work on specifically obj_enemy. I'm currently working on a game that will have about 20 different enemy types plus a few different boss characters, how would i be able to implement this code without repeating it for every unique type? a solution i was thinking of was to just change "obj_enemy" to "all" and just have some sort of switch case determine if the code should run, but surely there's a more elegant solution? I'd rather have, say, hitting walls or scenery not even be considered by the code if possible thanks!
@Pontuz
@Pontuz Жыл бұрын
make a parent for all the enemies and do the instance_place_list check with the parent
@sevlla5182
@sevlla5182 Жыл бұрын
did u manage to do it man? I'm trying to do the same, i have 2 enemies with diff object, idk how to do this, i already tried listing both objects and putting the list in the var hits but the enemy doesnt take damage this way
@MichaelNovakJrXD
@MichaelNovakJrXD 5 жыл бұрын
so when i jump in the air and attack, my charatcer stays in the attack animation and is stuck in the air and i cant do anything. why?
@SophiaTheTrick
@SophiaTheTrick 5 жыл бұрын
same here, if you resolve this please post the solution
@MichaelNovakJrXD
@MichaelNovakJrXD 5 жыл бұрын
Ivan Rowlands de Macedo will do
@wtflol6969
@wtflol6969 5 жыл бұрын
The new attacking state doesn't have any movement code in it so you'l have put in movement calculation in there. You don't need to declare variables or anything. Best thing to do is copy the movement code from your original o_player code and into a script and then call that script at the beginning of the attack state script. Then you can change wtv you want like gravity or walkspeed and it will only be that way while in the attacking state.
@maul8456
@maul8456 4 жыл бұрын
@@wtflol6969 can you put the code??
@cvalerinv
@cvalerinv Жыл бұрын
How do I include various objects? To be more specific how do I make the attack hit not only just one type of object. I thought it would be as simple as adding all the objects into the arguement but it just breaks it. any advice?
@Fuzzyplatypus
@Fuzzyplatypus Жыл бұрын
make all the objects as children of one parent enemy object, thats probably the simplest way
@iamturtleneck
@iamturtleneck 4 жыл бұрын
How do I change what direction the player is attacking in based on which direction they are facing? I can’t figure that part out. When I walk left and the attack animation faces right, it automatically attacks to the right. I duplicated and flipped the animation, now I just need to know how to program it to pick the right animation based on the direction
@zaythekid4769
@zaythekid4769 Ай бұрын
did u solve this issue
@Alex-rr1qc
@Alex-rr1qc 5 жыл бұрын
You are my hero bro
@marrero171ify
@marrero171ify 5 жыл бұрын
ds_list_destroy(hitByAttackNow); doesn't let me run the game. Anyone know the problem?
@jellytroid
@jellytroid 4 жыл бұрын
Helpful tutorial. The only thing is the player will freeze if attacking in midair. I followed the code closely, but have to restrict the player to only being able to attack while on the ground (which works fine for the game I'm working on, but just saying)
@WholeWhatBread
@WholeWhatBread 9 ай бұрын
How would one be able to do the attack animation but still continue to move along the path if attacking in the air?
@joshuavadrot4324
@joshuavadrot4324 4 жыл бұрын
how can i create a new enemy ? did i really have to create each time 3 new scripts for each enemy ?! like EnemyBlobState_Free / EnemyBlobState_Hit / EnemyBlobState_Dead and if i want to add some movement and attacks to my enemy i have to create EnemyBlobState_Move / EnemyBlobState_Attack ??
@wtflol6969
@wtflol6969 5 жыл бұрын
If want to be able to control how your player moves while attacking youll have to put all of your movement code into the player attacking state. The best way to do this is to instead make a new script and paste it there. Then you can take out anything you don't need or want to modify and call that script while in the attacking state. so you would have your player move into the Player_State_Attack and the first line would be PlayerMovementWhileAttacking(); or wtv. Took me a while to figure that out.
@spaghetto1810
@spaghetto1810 2 жыл бұрын
THANK YOU! I’ve spent a few days trying to figure out how to get attacking to work the way I want it to. Your comment totally helped!
@Grimsikk
@Grimsikk 2 жыл бұрын
This was such a big help, thank you so much! I copied my Collide and move code into a separate script and then called that script at the beginning of the PlayerState_Attack_Slash script. I also copied this into that new script to make sure that the player is facing the right way: if (hsp != 0) image_xscale = sign(hsp);
@wtflol6969
@wtflol6969 2 жыл бұрын
@@Grimsikk no problem. I forgot I posted this and have since forgotten everything I learned lool. But it was fun for a while!
@tjcola7703
@tjcola7703 5 жыл бұрын
the the tutorials, keep it up!!!
@zackonark2658
@zackonark2658 5 жыл бұрын
if(hits > 0) seems redundant to me as instance_place_list() would return a value of zero if there are no collisions, meaning the for loop wouldn't do anything in such a case
@atygr
@atygr 5 жыл бұрын
yo how do i keep my character affected by gravity/momentum during the attacks?
@DrJurdenPeterbergsteinlerwitz
@DrJurdenPeterbergsteinlerwitz 5 жыл бұрын
Can you put in the collision/gravity check into the script?
@creadzz_
@creadzz_ Жыл бұрын
PLEASE HELP!!! I copied the stuff from the step-event over to the script like you did (without the keyboard-checks), but when i try to run the game, it shows me an error that i didn‘t set the variables (right, left)… Ples help me 😢
@rosahiru2855
@rosahiru2855 4 жыл бұрын
When I try to run the game I get a local variable issue with hitID. Does anyone know how to fix it?
@onyourpocket8642
@onyourpocket8642 4 жыл бұрын
can someone explain to me what the "hit by attack" list does?
@christopherschneider2767
@christopherschneider2767 5 жыл бұрын
Was able to get the melee attack working while in the air, but now player object descends verrrrry slowly and wont jump, any ideas how to fix?
@zayJax
@zayJax 5 жыл бұрын
how did you make the player attack in the air tell me
@HeadFacethePirate
@HeadFacethePirate 4 жыл бұрын
I doubt anyone will see this before I figure it out myself but: I'm having trouble with getting it to reduce enemy HP properly. I'm trying to have it be every hit reduces the HP by 1. But I think the game is calculating this as every frame they're getting hit by = -1 hp. so one hit does like 5-6+ hp (or however many frames the hitbox is colliding with an enemy) instead of a flat amount
@donaldazevedo5554
@donaldazevedo5554 2 жыл бұрын
In reference to my script " EnemyHit(2) " I am getting an error saying "expected 0 got 1" What does this 2 do?
@n_coder
@n_coder 4 жыл бұрын
I went to this tutorial to learn how to set my character attack animation to happen and then go back to the normal sprite when it's done (since i'm doing a different combat style in my game) , i was planning to use the animation_end , but for some reason my gamemaker doesn't have this , so i tried the following If(keyboard_check(vk_numpad1)) { sprite index = spr_player_attacking; image_speed = 1; if (image_index = 3) { sprite_index = spr_player; } } But for some reason when i press 1 to attack , it only appears the first frame of the attacking animation , the animation only continues if my character keeps walking , what do i do ?
@tylertomooka5716
@tylertomooka5716 4 жыл бұрын
although it's probably too late, animation_end is a script resource, so you need to get the code from 27:10 and copy it into a script before calling it as a function
@n_coder
@n_coder 4 жыл бұрын
@@tylertomooka5716 oh geez that makes things a little bit harder , and u're not late , I still don't have experience in programmation so despite I already made the animation part I'm pretty sure I did it in a very good inefficient way , what i just did was : If (keyboard_check(numpad1)) { Sprite_index = spr_player_attacking; Image_speed = 1; Alarm_set [1,3] } Now I don't remember how to write an alarm but I activated the alarm 1 in 3 steps , and that alarm says spr_index = spr_player . As I said , despite it kinda works I'm pretty sure it's not very effective (mainly bcoz programming an animation to happen , end and then go back to the original is one of my biggest difficulties) , so thx very much for ur help
@alexandre_73
@alexandre_73 3 жыл бұрын
@@n_codermano vc ainda programa? Se programa consegue me ajudar com meu jogo?
@DigitalDog41
@DigitalDog41 7 ай бұрын
For my current version of gamemaker(lates 2023 version) the animation end wont work because spritespeed_framespersecond dosnt exist and neither the code download nor shaun show whats in there.
@felipesilva3732
@felipesilva3732 3 жыл бұрын
22:23 are there any other tutorials that i should watc before this one, because he doesnt show where should i pu tthis exactly, or how does this connects to the enemy and many other things
@timtime1455
@timtime1455 4 жыл бұрын
When i press the button the slash animation never ends, even though i'm using the "animation_end" script.
@timtime1455
@timtime1455 4 жыл бұрын
Btw im using the sprite for your new action rpg if that helps
@Th3Gam3Guru
@Th3Gam3Guru 4 жыл бұрын
Is there a tutorial available for the moving background?
@fatalerror7453
@fatalerror7453 4 жыл бұрын
My player just gets stuck in the air if i melle in air i suppose i could just do a check and only allow playerto attack on ground
@breakfastboygaming
@breakfastboygaming Жыл бұрын
Does this code work with the code you wrote in your making a platformer playlist?
@ohgross
@ohgross 3 жыл бұрын
When I move the basic step code to the script I am getting a compile error: Variable .y(1, -2147483648) not set before reading it. Any suggestions?
@christianbaxter1565
@christianbaxter1565 3 жыл бұрын
do you have function whatever the name of the script is() { every line of code}
@dapperman1027
@dapperman1027 3 жыл бұрын
im having the same problem
@lsuperparal
@lsuperparal 5 жыл бұрын
Question, is there any reason to use scripts and not user_event for state machine, or is it just a matter of choice?
@superstarichiban
@superstarichiban 5 жыл бұрын
Do you mean the event_user function? I believe that it's his preference in terms of programming style, but I am unfamiliar with the utility of that function as compared to using a script. From a fellow dabbler's perspective, I feel like scripts are far more modular and can be easily exported for use in other projects within Game Maker Studio and are in general a better practice due to how clean they make your code look. Having to dig through multiple objects in search of a specific event function that needs to be tweaked is far less elegant than opening the scripts list on the right hand side and looking there.
@lsuperparal
@lsuperparal 5 жыл бұрын
@@superstarichiban my question is only regards state machine of an object. like EnemyState_free/dead/hit ... you will only use this script inside enemies,, só why dont use the enemy event_user for this? Makes your code even more cleaner than have scripts outside the only object that use it. But anyway, both ways work!
@raylolpez6651
@raylolpez6651 5 жыл бұрын
Well one major benefit to using scripts I think is that you’re limited to only like 16 user events per object, but you can write a pretty much unlimited number of scripts. But if you don’t need that then I’d say it’s up to preference
@PixelatedPope
@PixelatedPope 5 жыл бұрын
As you start building more and more states for more and more objects, you'll find that many objects can actually share state logic. So while I understand the desire to keep all code for an object within that object, user events aren't a great fit for this. Additionally, user events have a processing overhead 4x that of scripts. Now, this is a very, very, very small amount of overhead, but it is there. And as others have mentioned the 16 event limit would be a bummer for more complex characters.
@lsuperparal
@lsuperparal 5 жыл бұрын
Thks for the answers guys!
@DemonkaiMugen
@DemonkaiMugen 3 жыл бұрын
could i use this to create for the Devkit of my Xbox Series S? ive been find the best developer software. i thought Unity would be smooth but it seems unstable, slow and Buggy. i got the latest version but wasnt a smooth experience for the past two days now so i want to give this a shot before i try Unreal engine Next. And yes im aiming to create a 2D platformer. i draw. sprite and have some coding knowledge.
@thebulbamachine4789
@thebulbamachine4789 4 жыл бұрын
someone help I tried attacking in midair and my character is stuck on the first frame, falls super slowly, moves super fast horizontally, and once he reaches the ground, his jump is tiny.
@blockcabin
@blockcabin 4 жыл бұрын
i had that same issue. i fixed it by putting all my other animation code (that wasn't tied to the attacking animation) into the player state free script
@alicewe_
@alicewe_ 3 жыл бұрын
great video! but in which video did you write the scripts for the enemy?
@tiagox3275
@tiagox3275 Жыл бұрын
2 years later and I'm wondering the same thing right now...
@Puppybarkk
@Puppybarkk 5 жыл бұрын
I was littarly about to look this up but then I get a notification tyyy
@coolsbruh
@coolsbruh 5 жыл бұрын
Can you do a tutorial on delta time next? I've been searching for tutorials on KZbin but never found any good ones. Delta timing is really important for fixing lag, and other game engines like Unity already have delta time built in. Thanks
@Karak-_-
@Karak-_- 4 жыл бұрын
GMS has delta_time variable built in, it have amount of microseconds that happened between frames. So movment per frame can be counted as movement per seconds *delta_time/1000.
@babypinksnail
@babypinksnail 5 жыл бұрын
By this time tomorrow all comments will be saying the character looks like Kris from Undertale, but you're wrong, the colors are wrong and so is the hairstyle somewhat. This is actually Ahrac from Nutdealer
@Codamations
@Codamations 5 жыл бұрын
BabyPinkSnail I have a channel that does speedpaints, animation and coding and animation tutorials, and funny and storytelling animations please consider subscribing
@babypinksnail
@babypinksnail 5 жыл бұрын
@@Codamations No thanks I dont particularly like people I dont know coming to me and asking me if I wanna sub to them, but I appreciate the offer.
@aiicarus6765
@aiicarus6765 2 жыл бұрын
How can I adapt this for an 8 directional movement system?
GameMaker Studio 2 - Multiple Collisions Tutorial
10:08
Shaun Spalding
Рет қаралды 17 М.
The 15 Commandments of Game Maker
16:32
PixelatedPope
Рет қаралды 123 М.
Iron Chin ✅ Isaih made this look too easy
00:13
Power Slap
Рет қаралды 36 МЛН
Playing hide and seek with my dog 🐶
00:25
Zach King
Рет қаралды 34 МЛН
Beginner GameDev Mistakes - Ep 1
6:40
Shaun Spalding
Рет қаралды 162 М.
I Made a 1D Game 🎮
11:18
Mashpoe
Рет қаралды 1,7 МЛН
How I Made a 3D Platformer in 2D Game Engine
21:23
ggenije
Рет қаралды 455 М.
Object States | Game Maker Studio 2
22:21
FriendlyCosmonaut
Рет қаралды 134 М.
RESOLUTION guide for game devs & GameMaker
8:50
Shaun Spalding
Рет қаралды 56 М.
Making Minecraft from scratch in 48 hours (NO GAME ENGINE)
16:38
I Made A Difficult Game About Climbing
15:04
Pontypants
Рет қаралды 2 МЛН
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4 МЛН
8 Awesome Indie Games Made with GameMaker [2018]
10:42
Ask Gamedev
Рет қаралды 312 М.