Patrolling Platformer Enemy - Godot 4 Platformer Tutorial - Part 7

Hope you guys enjoyed the video and let me know if there is any other functionality you'd like for enemies in future since we will introduce more, have a nice day everyone!
Come watch me stream!
kick.com/gamedevknight
Endless Nite - gamedevknight.itch.io/endless...
Buy me a coffee - ko-fi.com/gamedevknight
Discord - / discord
Instagram - / gamedevknight
twitter - / gamedevknightt
0:00 Intro
0:08 Melee Hit Fix
0:42 Enemy
1:24 Enemy AI
5:32 Enemy Killing Player
7:38 Killing the Enemy
9:34 Outro

Пікірлер: 74

  • @MoviesForMyDaughter
    @MoviesForMyDaughter6 ай бұрын

    Collision: 7:10 Layer = what that object is (helps greatly to name the layers first in Project Settings) Mask = what that object sees

  • @user-kg6dp6ie4i
    @user-kg6dp6ie4i9 ай бұрын

    really, series like this one are really helpful when you can't find any help and find one it makes you happy, really love this series please keep making more content like this in future 😊

  • @GameDevKnight

    @GameDevKnight

    9 ай бұрын

    Thank you for the comment friend, I'm just having a little break then I will continue this series and make more in 3D

  • @accumulator4825
    @accumulator4825 Жыл бұрын

    Dude I REALLY loved this series, thank you so much for making this. Could you please do a tutorial on adding a oxygen supply timer that runs out when you're under the water. With like 4 bubbles appearing over your head when you submerge? Otherwise it would just be sick if you could add voice sounds to the characters in the game and some other sound effects, and show us how to do that. But up to you. This was a short and sweet series. I'd understand if you want to leave it at that and start the next thing.

  • @talmalobani3144
    @talmalobani31445 ай бұрын

    thank u wonderful video!

  • @artofeugeneseguiban2773
    @artofeugeneseguiban2773 Жыл бұрын

    Let's goooooo 🎉🎉

  • @arlekino8848
    @arlekino8848Ай бұрын

    Excellent! How would you make it so that when you come into contact with an NPC it makes another animation?

  • @Konkoli119
    @Konkoli11911 ай бұрын

    Hi! This tutorial, it is the best! Thank you! I have a question too. In the begining of the video (at 0:26) when you fliping the Area2D, souldn't we have to flip the AttackArea insted? I mean I tried it and it worked for me, I'm able to attack left now :D

  • @GameDevKnight

    @GameDevKnight

    11 ай бұрын

    You can flip either I just decided to flip the area 2D incase I add anything to the attack area, but good job bro!

  • @Tee-bd2kt

    @Tee-bd2kt

    8 ай бұрын

    ​@@GameDevKnightPlease I'm having issues with flipping the player's Attack area, I tried your method but then my character keeps disappearing from the screen. Do you have any idea about what I'm doing wrong ? I love your tutorials by the way, they are really helpful.

  • @Tee-bd2kt

    @Tee-bd2kt

    8 ай бұрын

    ​@@GameDevKnight Don't worry anymore, I fixed it using a Marker2D node.

  • @SFoX-On-Air
    @SFoX-On-AirАй бұрын

    Am I missing something? How is that flip function flipping the whole animation and the point where the raycast is as well?

  • @313_V3rtX
    @313_V3rtX4 ай бұрын

    Nice tutorial video bro!I would really appreciate it if I could help me on something…In the last animation the “Die” one I follow every step I also made the animation with the keys and the queue free key but it just don’t work…I did all the code too but when I run the game it just don’t play the animation.I triple checked it but nothing…What can I do?

  • @GameDevKnight

    @GameDevKnight

    4 ай бұрын

    I'm not too sure, are you sure you selected the right node to queue free on? you need to make sure it's the actual enemy, or in your code just make another function called destroy_self where you queue free, and call that function in the animation just to be sure

  • @Dragon-gq9jw
    @Dragon-gq9jwКүн бұрын

    how would you do the bounce if there is a wall on one side and no wall on the other side?

  • @MasterZguy
    @MasterZguy26 күн бұрын

    for anyone who is having issues for the melee hitbox not flipping here is the soulotion!! 1 - delete the lines that flip the hitbox along with the lines that flip the player when he is walking 2 - replace them with this : var isleft = false if velocity.x isleft = true sprite_2d.flip_h = isleft $AttackArea/CollisionShape2D.position.x = (FLIPPED POSITION) # REMOVE THE BRACKETS OR () AND PUT YOUR NUMBER if velocity.x > 0: isleft = false sprite_2d.flip_h = isleft $AttackArea/CollisionShape2D.position.x = (ORIGINAL POSITION) # REMOVE THE BRACKETS OR () AND PUT YOUR NUMBER 3 - go to your player and put the area 2d or the attacking area in the 0,0 positons and instead move the collider or the COLLISON BOX 4 - after moving the collison box check the position and put it inside of the script in the line that says (ORIGINAL POSITION) 5 - Go to your player sprite > OFFSET > and flip_h to true 6 - now position the COLLISION BOX to the flipped position and then put it in the FLIPPED POSITION **this is a better way to handle it since scaling the collision box wont do any thing at all since it will flip it in place.**

  • @longuemire748
    @longuemire7485 ай бұрын

    Thank you for this tutoriel (sorry for my english) Shouldn't "$AttackArea" be scaled instead (0:25)?

  • @GameDevKnight

    @GameDevKnight

    5 ай бұрын

    Do you mean how big it is?

  • @longuemire748

    @longuemire748

    5 ай бұрын

    @@GameDevKnight Not to swap the sword's area. Or maybe I misunderstood, I thought that's what the scale was for?

  • @mato_oppita3167
    @mato_oppita31679 күн бұрын

    4:57 hi, I tried to follow you tutorial but whenever my character touches a wall it disappears, any idea why?

  • @dimtool4183
    @dimtool41839 ай бұрын

    Just on the last animation, enemy is missing a frame when dying, because queue_free() happens exactly when the last frame key plays (I also ran video at x0.25 to confirm). So need to make animation 0.4 sec long and place that queue_free() key on the 5th spot. You maybe fixed it in some later tutorial though.

  • @GameDevKnight

    @GameDevKnight

    9 ай бұрын

    Oh thanks for letting me know I didn't notice

  • @blueberrys1381
    @blueberrys13813 ай бұрын

    thank you for tutorial bro but I mean at 0:23 it actually $AttackArea

  • @storablespore0823
    @storablespore08235 ай бұрын

    The Enemy can hit me Fine if the hitBoxes collide but if i Attack it. It dosent do Anything. I wrote the same code and it still dosent work

  • @GameDevKnight

    @GameDevKnight

    5 ай бұрын

    if you are trying to hit the enemy while he is on the left that is broken, I fix that in the next video, but if it doesn't work hitting him on the right first check then come to discord and send some screenshots

  • @srmistick7706
    @srmistick770610 ай бұрын

    This tutorial series is amazing! I wanna ask though because I'm currently having some difficulties in regards to the code for killing the enemy because it does not tend to work in my end. I assume that it's because the AttackArea of the player is not registering the enemies which is odd because it seemed to work when I was following the 6th video. Is it possible if you can help me out? Thank you so much!

  • @GameDevKnight

    @GameDevKnight

    10 ай бұрын

    I have a discord server linked in the description of the videos, feel free to come send some screenshots of your project and I can try to help out, there's a few different thing's that could be wrong, I'm sure we can work it out together my friend.

  • @srmistick7706

    @srmistick7706

    10 ай бұрын

    @@GameDevKnight I was actually able to get it working a while ago, turns out I did a mistake in the layers for both the player and the enemy. I'll try to ask through discord if I were to have any other trouble in the future, thank you once again!

  • @GameDevKnight

    @GameDevKnight

    10 ай бұрын

    That's completely fine man there's actually been 2 or 3 people who did the same, in future I will start editing videos a bit more like zooming in and drawing lines under what specifically we're focusing on, I'm glad it worked out bro!@@srmistick7706

  • @mistakemaster6882
    @mistakemaster68823 ай бұрын

    I have an issue where my enemy is just falling off the ledge whenever it reaches it. The raycast just doesn't seem to be detecting it for some reason

  • @anonymousl299

    @anonymousl299

    3 ай бұрын

    Check raycast if it is in proper postion and try to change version of godot or try again maybe a bug of godot

  • @CuriousMonkey716
    @CuriousMonkey716Ай бұрын

    5:50 It keeps on saying that "Player is not in the current scope" :(

  • @Cross_Contam
    @Cross_Contam7 ай бұрын

    Between if !Raycast is colliding and is on floor there is a symbol you used in the place of "and" that I do not have on my keyboard.. how do you make that symbol? Looks like " or bb I used "and" instead of the symbol it works after adjusting the ray to point diagonally upward for walls otherwise pointed down it would flip uncontrollably. I have ramps in my level and when going down a steep ramp the enemy will just float until it hits a wall then will stop and get stuck in the air against the wall. It would be nice if gravity was applied throughout the entire process so that if the enemy were to get air born he would just fall back down. Perhaps I'm missing something somewhere.

  • @TimberLine534

    @TimberLine534

    4 ай бұрын

    The symbol is called ampersand, &. You should have the letter on your keyboard, look to the seven above the alphabet key, and it should be right above it. To use &, all you have to do is press either shift key and hold it as you press seven. Don't worry, I don't even know what and how all the keys work.

  • @sumaia9495
    @sumaia949518 күн бұрын

    love the tutorial, but you didn't really clarify what the sprite2D, collisionShap2D, Hitbox, and collisionShape2D were for.

  • @bobro1005
    @bobro10052 ай бұрын

    it wont let me connect the area2d node into the enemy?

  • @redwolf6334
    @redwolf63342 ай бұрын

    I was wondering how you could do this but with an enemy that turns when they collide with a wall instead

  • @linasjaniques

    @linasjaniques

    2 ай бұрын

    Maybe if you point the raycast forward instead of downward should do the trick. Just remove the exclamation point before "is_colliding". But this will make it flip even if it collides with something else, like the player or another enemy, so you will need to work with layers or groups.

  • @Woof-Tastic671
    @Woof-Tastic67117 күн бұрын

    why is my enemy not doing the animation when it gets hit

  • @MohammedEssamSaleh
    @MohammedEssamSaleh11 ай бұрын

    Goood

  • @Joyblaster
    @Joyblaster9 ай бұрын

    ] Move and collide() = collide with bodies. Ex. You can push player2 with player1 () But if you don't use move _and_ collide _() Then Player can't push player2 from your player force. [2] move_and_slide = Make a triangle (slope) static_body. Put you player on it. There are slope but player doesn't slide. His position is = 0. But you use move_and_slide() You can slide from slope. i checked it . there are many functions that we should check. There is also a awesome func look_at() I tried to make ememy like 🐝 in hollow knight but i never make it. But you want make ememy like 🐝 Then there is 3 lines of code you should write 🐝 Script onready Var Player = get_node("../player") Physics process (delta): self. Position += (player.position - position)/20 Look_at(player.position) Don't run (🐝 tscn ) because you don't have player So make world tscn put player and enemy Enjoy hollow knight like 🐝 enemy If find helpful, then like it 😎

  • @GameDevKnight

    @GameDevKnight

    9 ай бұрын

    That's interesting man I haven't looked into how the functions actually work I'm still learning Godot, the tutorials are for me to understand things better myself that was helpful!

  • @sheeveman7568
    @sheeveman7568Ай бұрын

    How do i make my enemy walk off a wall

  • @user-dw3ei4xn8w
    @user-dw3ei4xn8w4 ай бұрын

    Heyy Appriciate the video I just have a problem when i try to run the game after setting up the enemy turning left and right it says " Attempt to call function 'is_colliding' in base 'null instance' on a null instance

  • @GameDevKnight

    @GameDevKnight

    4 ай бұрын

    so the null instance means it has lost reference to the raycast or it's never set in the first place, just make sure it is properly being set with the onready var

  • @user-dw3ei4xn8w

    @user-dw3ei4xn8w

    4 ай бұрын

    @@GameDevKnight Thanks so muchhh I just fixed it and it works perfectly♥️

  • @and.n6799
    @and.n679910 ай бұрын

    On the “if area.get_parent() is Player:” for the enemy hitbox It says the Player is in current scope… pls help 😭

  • @GameDevKnight

    @GameDevKnight

    10 ай бұрын

    I'm pretty sure the reason for that is the player is not declared, in the top of your player script make sure you have class_name Player, it should fix your problem

  • @menoobsad

    @menoobsad

    9 ай бұрын

    @@GameDevKnight thanks i was having the same problem now its gone

  • @theBSH

    @theBSH

    6 ай бұрын

    you can also add the play to a group and use is_in_group()

  • @lakijacim3008
    @lakijacim30086 күн бұрын

    I am doing the same project as you and i also have a problem with dying animation please help me about this. Thanks!

  • @Pao-2804

    @Pao-2804

    3 күн бұрын

    Did you find out? I'm having the same issue. The player don't die when colliding with the enemy

  • @lakijacim3008

    @lakijacim3008

    3 күн бұрын

    @@Pao-2804 during game i found out that my player is only fighting things on the right side when he turn on other one he doesn't. My player dies normally, i'm also using 4.2.2 version of Godot maybe it changes something i'm not sure ,i'm in this engine about 60 days.

  • @user-lp3ji9ex4p
    @user-lp3ji9ex4p9 ай бұрын

    One problem it says enemies not declared in current scope

  • @GameDevKnight

    @GameDevKnight

    9 ай бұрын

    So you need to make the group Enemies in your godot project, you can click on your sabertooth and at the top right by node you can select groups and create a new one called Enemies and assign the Sabertooth scene to it

  • @_DOM_898
    @_DOM_8983 ай бұрын

    5:04 my enemy just disappears after getting near an edge

  • @maybesomething0

    @maybesomething0

    3 ай бұрын

    Same

  • @thelosteco9139
    @thelosteco9139Ай бұрын

    I think am kinda late but any way when I try to hit the enemy nothing happens no matter where I hit from. I checked the code everything is correct. I will be very grateful if you or someone help me......

  • @Pao-2804

    @Pao-2804

    3 күн бұрын

    Did you find out? I'm having the same issue. The character don't die.

  • @thelosteco9139

    @thelosteco9139

    3 күн бұрын

    @@Pao-2804 nope. I didn't find it. I started watching Brackeys. Also recommend you to watch...

  • @user-oj1yr8gh5f
    @user-oj1yr8gh5f3 ай бұрын

    Sir enemy is widing out it is not working Help!!

  • @GameDevKnight

    @GameDevKnight

    3 ай бұрын

    what do you mean by widing out? Come to discord to send screenshots of what's happening

  • @redx90525
    @redx905255 ай бұрын

    my character isn't on the edge though

  • @GameDevKnight

    @GameDevKnight

    5 ай бұрын

    just put the raycast closer to the enemy

  • @redx90525

    @redx90525

    5 ай бұрын

    no like it's not on a platform it's just patrolling normally

  • @didikas_58-wilaya
    @didikas_58-wilaya4 ай бұрын

    i am arabi but i love you brather

  • @GameDevKnight

    @GameDevKnight

    4 ай бұрын

    I love you too brother

  • @hyzohyzo6850
    @hyzohyzo68506 ай бұрын

    bantu aku, musuh tidak flip saat menabrak colission

  • @anthosm6498
    @anthosm64984 ай бұрын

    Im trying very hard to learn fr, so i had a lit bit of troubles flipping the area; if sprite.flip_h == true: collision.position.x = abs(collision.position.x) $AttackArea.position.x = abs($AttackArea.position.x) $Area2D.position.x = abs($Area2D.position.x) elif sprite.flip_h == false: collision.position.x = -abs(collision.position.x) $AttackArea.position.x = -abs($AttackArea.position.x) $Area2D.position.x = -abs($Area2D.position.x) I did the whole movement script by myself and idk why instead of what he shows in the video this was the thing that worked for me. I hope this helps someone :D

  • @GameDevKnight

    @GameDevKnight

    4 ай бұрын

    Good work man, I think the problem is you're meant to change the scale not the position, the scale.x, you got this bro

  • @anthosm6498

    @anthosm6498

    4 ай бұрын

    @@GameDevKnight When I do it with the scale.x my character keeps spinning 😅, probably because I messed up somewhere else in the coding 😂. But once I'm done with all the videos I'll try to do the whole project again.

  • @prueee7856

    @prueee7856

    3 ай бұрын

    @@anthosm6498 There is an Issue/Problem with change positive scale to negative. Sometimes, like in my Game, the Enemy's rotation change to 180 degrees and scale.y change to -1. Idk why, but they say its logical but idk :D There are some better workarounds than using scale = scale * -1

  • @anthosm6498

    @anthosm6498

    26 күн бұрын

    @@prueee7856 I was messing around and I found that the scale is by default bonded. You have to manually go to the scale in the instructor and separate them :v

  • @MohammedEssamSaleh
    @MohammedEssamSaleh11 ай бұрын

    Goood