Nice video man! I've got a few tips/suggestions though. Instead of using `has_method`, and adding dummy methods for making sure you are looking at a particular type of object, you could use `class_name`. So you would have, for instance `class_name Player` at the top of your file, and then check `if body is Player`. This way you don't have to add an empty function. It also has the added benefit of making it appear in the node search, which can be very useful if you want to create, say, a reusable health or hitbox component. I would also caution against hard coding damage values in your `_on_hitbox_area_entered` function. This kind of system could become very unwieldy once you have multiple enemies. Say you have 5 different enemies and then decide that, actually arrows should do 60 damage. You now have 5 places you could forget to update it. A better system might be to keep that info in the arrow itself, and access it when you are applying damage. So you'd have `take_damage(weapon.damage)` in your function, and only one place to update if you think arrows should do more or less damage.
Another approach I've seen out there as an alternative to has_method is to place the player into a group such as "Player". You can then just call `body.is_in_group("Player")`
I added your idea for the player class name and it worked as you said (thank you) but I also left the player has_method in case I had a function that needed to call a function on the player. No idea if that's right or not, but it works. I read in so many places not to use or rely on groups because forgetting to add something is a nightmare debugging. The class name just works. And I totally agree on having the arrow pass the amount of damage to the enemy. What if you used wood arrows vs. metal arrows. :D
putting the damage variable on the arrow is definitely the way to go. This series is definitely geared towards complete noobs like me who can more readily follow the hardcoding style of having the relevant variables on the thing that's interacting with them, and it's great for teaching in a small environment like this, but scaling this up to a bigger project would be exhausting. Thanks for the pointer, I've moved my damage stat over to the arrow and it works great ^.^
for anyone else wondering how to implement damage from the area, you need a var damage = 50 in the arrow node and then when the slime detects the arrow area, you can call take_damage(area.damage)
Thank you, this one worked perfectly. But if I may; I changed the death of the slime to spawn the slime_collectable then queue_free, just like the code in the apple tree. Brilliant,. Then I set up the slime_collectable just like the stick so it just sits there waiting for the player to walk over it and pick it up. It seemed more natural that way. I am so thankful of your little apple tree video. I'm not a fan of 2D but I've learned so much so far.
this is the way I chose to set it up, but I'm glad this video exists anyways because it shows a different approach that may be useful later, for say if you want to guarantee a boss drop goes in your inventory so you don't accidentally walk away without it. Very cool, thanks for the idea!
Hey DevWorm, First thanks for making this series its fun and informative. For the slime loot. I think one could also have the slime's death instantiate a copy of the slime collectible scene. Model it off of the stick resource then the player can pick it up by hitting its collision shape. This might save some time with disabling the slime collectible and its collision shapes. It would also prevent the crash if the player did not enter the collision shape 2d on the slime itself.
Youre a great guy bro, once i get my finances back on track i will send you some donations , very informative and i like how you correct your mistakes and explain the logic in a very understandable way for someone like me who is just getting started. ❤
aw dont worry about the money brother! just learn! I'm here to try and teach.. you should save that money and work with a professional developer one-on-one! but it means the world that you find these tutorials helpful! thank you and with your determination to improve you are going to do something truly amazing!
If anybody was having issues with the calculation of the player position in Godot 4.2, this is what worked for me: position += (player.position - position).normalized() * speed * delta Idk what was happening, but the enemy seemed to move out of the screen and get stuck
I think, and im a bit newbie, that u could simply drop the slime collectable and work with it like the stick, if u pass through u pick it if u don't it disappear after certain time, because we could not want to pick some type of drops... but anyway gj im learning a lot, hope u can keep with the series :)
Hello, Ive just recently got into coding and found this tutorial its super helpful and clear but I noticed there was no damage for the player any suggests on how i might add that thanks ❤
so just like when we created damage for the enemy, it is along the same lines of that! instead you have to put an area2d on the arrow and connect it to check if it enters the player.. and if so then you can change a health variable and function whatever you want to happen when the health is changed or if it equals 0 then to hide the player or play the death function!
@@dev-worm happy to do some ensemble collaboration if you're interested. Basically we rotate as driver/navigator while we work on a game. 🙂 It's a process we use all day at work, I love it.
Can I ask why you chose to use the giant collision shape to find the player as opposed to an onready variable with the get_node() function & an absolute path to the player?
Congratulations on another impeccable video. Now I have a very lively enemy to fight against. I just have one suggestion and one question. Suggestion: for future videos, it would be very kind if you tried to keep the script window a little larger to make viewing easier (just a note from a follower with low vision). Question: when I get the second slime, the label number appears behind the slime icon in the inventory. This only occurs for slimes, the number of apples and sticks appears over the respective icons. Could you instruct me on how to fix this? Thank you very much
reviewing the previous videos, I realized what might be the source of the problem: in the inv_UI_slot scene I added item_display as a child of CenterContainer and not as a child of Panel. However, when I simply try to pull and release item_display to make it a child of Panel (prior to Label), the game breaks, no longer running in DEBUG. Please, what procedure could I take to fix this without breaking the game?
hmmm.. uh i would have to think that a certain slot is messed up but if you've played the game and picked the items up in different orders and it is still only messing up with slimes then I'm not sure... I'm sorry but id have to look at it. I'm very sorry. if you still haven't got it resolved then try and explain it a little more and maybe I could figure it out by looking at my copy of the game. i'm really sorry and i hope im able to help!
@@dev-worm Many thanks for the reply. There is no need to worry about me in this regard. After you finish your course here, I will redo everything once again, so that I can better understand the processes and concepts in my mind. I have no training in this area and I am learning completely from scratch with some tutorials here on TH-cam. It's worth pointing out that your videos have been the most inspiring and productive for me. Please keep up the great work!
Im sorry to say I am encountering the same issue as I had in the video about creating an enemy as part of your creating an RPG tutorial. The enemy just yeets off into the distance when I enter the detection_area CollisionShape2D. Changing the speed (counterintuitively making the var a bigger number so it walks slower, because of the divide by speed in line 19) it walks right past me on to bigger and greater adventures. I know I haven't even added in the attack animation at this point, but this enemy is just being really passive aggresive about it!
hi. i had this issue, then realised the issue. i had "possition += (player.position - position / speed)" instead of position += (player.position - position) / speed
Wondering, why wouldn’t you just create a preload reference to the collectible and then instantiate it, then queue free the actual slime. Would make you not have to deal with all the visible disabling and what not, and would be cleaner down the road like if you wanted to keep track of enemies in the world or collectibles in the world ( like when you want a enemy limit or minimum or when you want a collectible limit ). Then just give the collectible the same script as the stick
check out the recent "how to create combat system" that is part of the hack'n'slash series that I uploaded about a week ago!! It covers this really well!
im having abit of an issue with the collisions . for example, if i stand next to a collider and the slime pushes me, i will just clip through . and the slime just phases through all collisions on the tilemap. edit: i changed my collider on the player to a capsule shape and that fixed the first problem edit 2: just added move_and_slide( ) to the physics process and now slime collides .
Any idea on why I get the error "Invalid set index 'visible' (on base" 'null instance') with value type 'bool'. It doesnt like the code "drop_slime()", and "slime.visible = true". Ive gone back and double checked things but cant seem to find what I missed.
I keep getting the same code but instead of "null instance" mine says "staticbody2d" Edit: My fix ended up being that I spelled Visible as Visable. The person above was right about spelling error. Hope that helps
that's very easy, you just have hitbox and health box nodes, and add them to the player and enemies, just set up the collision layers correctly so that they interact with each other. (I am using a translator, I speak Spanish). If you like, I'll give you the script for the created nodes.
Ich versuche das hier mal auf Deutsch. Ich habe folgende Probleme... 1. Wenn ich in der Range vom Slime einen Stock einsammel verschwindet auch der Slime (Enemy). 2. Seit ich das Arrow system eingebaut habe folgt mir der Slime nicht mehr.
man ,are you going to make video about godot 4.2 this uptade awesome has alot of Abbreviation and alot of improvment for both three d and two d this uptade is very amazing you have to talk about it
@@scoringfish1588 # Movement Speed Settings var speed : float = 0 var speedup : float = 3 # Amount of speed to add while speeding up var slowdown : float = 3 # Amount of speed to subtract while slowing down # All movement related functionality goes here func handle_movement(): var moveDirection = Input.get_vector("Move_Left", "Move_Right", "Move_Up", "Move_Down") ## Player movement handler ## If there is a movement direction increment speed by speedup and clamp to maxSpeed to avoid infinite speed increase ## Else the player is no longer commanding movement and we slow down the speed by slowdown. We increment down speed so ## that if movement is resumed while slowing down it increments up from where it was and not 0 if (moveDirection): speed = clampf(speed + speedup, 0, statsManager.playerStats.maxSpeed) velocity = moveDirection * speed else: velocity.x = move_toward(velocity.x, 0, slowdown) velocity.y = move_toward(velocity.y, 0, slowdown) speed = move_toward(speed, 0, slowdown) move_and_slide()
I deleted my other comment as it was just me thinking out loud, and this isn't really the place for such a hypothetical discussion. Now there is a few things I wanted to point out. Your "dead" variable doesn't need to be initialized in the ready function. It is already initialized when you wrote it out. On your await function, you can have it wait for the animation_finished signal to trigger. Don't give it the name of the animation, it just doesn't work that way anymore, from my experience. When doing logical statements, you don't need to write a separate section for the true part. In fact you could have just put that before or after your if block, or use an else statement in your if block. If !dead: else: This is useful if you don't want certain code to execute unless the oposite of your if statement is true. This is just syntax suggestions, your way still works. To stop your animation in your death function, just call the stop function lol; you don't have to hide it.
I could not find a way to know when the animation finished, so I set my timer to 0.8 seconds. There seems to be a signal but it never fired. AnimationPlayer works great but AnimatedSprite2D doesn't on my game.
Help :( I'm making a game where I'll have two groups fight each other. I used the same code from the video for the two groups but one's method is enemy and the other knight. However, if characters from the same method collide with each other, they kill each other (lol). Does anyone have any suggestion as to why that might be? I'm a noob at game dev. Thanks!
maybe you have to write: func _on_detection_area_body_entered(body): if body.has_method("player"): player_in_area = true player = body func _on_detection_area_body_exited(body): if body.has_method("player"): player_in_area = false
Im curious is there a way to make it so the item that drops "slime" just disappears if im not in the detection area like if im far out of the area and end up killing the slime because i have a further camera zoom so i can see more... i kill the slime out of range it drops and crashes i know you maade the detection area to pick up the slime in a larger area but what if we wanted to just kill the slime and move on without picking up the item or just killing it from out of that range it would make the game crash any work around to that?
Hi! use the same code as dropping the apple. Make the slime_collectable scene just like the stick, so it's collectable and change the slime scene to instantiate it into the world, then queue_free the slime monster. Tha6t way you don't have that huge area to deal with and the player gets to collect the slime or not. You could set a wait timer on the slime_collectable to kill itself after a minute so it's not stuck in the world. :)
I am getting an error and a game crash with the line; position += (player.position - position) / speed Error; Invalid get index 'global' (on base: 'CharacterBody2d (player.gd)'). I've tried using chat gpt to help me out but I still don't understand Edit; I went back to one of your old tutorials and added these two lines of code, I had to turn the speed down though; var direction = (player.position - position).normalized() position += direction * speed * delta
This is what I did to make the player have to go collect the dropped loot. In the slime script do this: func drop_slime(): slime.visible = true $slime_collect_area/CollisionShape2D.disabled = false
func slime_collect(): slime.visible = false player.collect(itemRes) queue_free() func _on_slime_collect_area_body_entered(body): if body.has_method("player"): player = body slime_collect() Shrink down the rat_collect_area>CollisionShape2D so the player has to get to it.
yes looks really good!! goodjob Zahardnik3.. im so happy to see you spending so much time trying to learn and get everything right!! it is really amazing to see!
I got an error for trying to collect the item. Invalid call. Nonexistent function 'collect' in base 'Nil'. I have no idea why it works for the stick and apple collectables, but not the slime_collectable from the Slime. It highlights this line of code: player.collect(item) It's supposed to work just like the stick (walk over it and you pick it up). The full function code is this: func slime_collect(): await get_tree().create_timer(1.5).timeout slime.visible = false player.collect(item) queue_free() --------------------------------------- I basically copied and pasted for the same interactable area body code. I also have this code: @onready var slime = $slime_collectable @export var item: InvItem Can someone help me out, please? idk what to do, the system just doesn't view "collect" as a function. And yet, it views it as a function in my other scripts like for the stick and apple.
Nice video man!
I've got a few tips/suggestions though.
Instead of using `has_method`, and adding dummy methods for making sure you are looking at a particular type of object, you could use `class_name`.
So you would have, for instance `class_name Player` at the top of your file, and then check `if body is Player`. This way you don't have to add an empty function. It also has the added benefit of making it appear in the node search, which can be very useful if you want to create, say, a reusable health or hitbox component.
I would also caution against hard coding damage values in your `_on_hitbox_area_entered` function. This kind of system could become very unwieldy once you have multiple enemies. Say you have 5 different enemies and then decide that, actually arrows should do 60 damage. You now have 5 places you could forget to update it.
A better system might be to keep that info in the arrow itself, and access it when you are applying damage. So you'd have `take_damage(weapon.damage)` in your function, and only one place to update if you think arrows should do more or less damage.
Another approach I've seen out there as an alternative to has_method is to place the player into a group such as "Player". You can then just call `body.is_in_group("Player")`
I added your idea for the player class name and it worked as you said (thank you) but I also left the player has_method in case I had a function that needed to call a function on the player. No idea if that's right or not, but it works.
I read in so many places not to use or rely on groups because forgetting to add something is a nightmare debugging. The class name just works.
And I totally agree on having the arrow pass the amount of damage to the enemy. What if you used wood arrows vs. metal arrows. :D
putting the damage variable on the arrow is definitely the way to go. This series is definitely geared towards complete noobs like me who can more readily follow the hardcoding style of having the relevant variables on the thing that's interacting with them, and it's great for teaching in a small environment like this, but scaling this up to a bigger project would be exhausting. Thanks for the pointer, I've moved my damage stat over to the arrow and it works great ^.^
for anyone else wondering how to implement damage from the area, you need a var damage = 50 in the arrow node and then when the slime detects the arrow area, you can call take_damage(area.damage)
This series is really well made, thank you for creating high-quality content fellow TH-cam teacher! 😊
Hello fellow TH-cam teacher! So happy to hear that!! Thanks!!!
Thank you, this one worked perfectly. But if I may; I changed the death of the slime to spawn the slime_collectable then queue_free, just like the code in the apple tree. Brilliant,.
Then I set up the slime_collectable just like the stick so it just sits there waiting for the player to walk over it and pick it up. It seemed more natural that way.
I am so thankful of your little apple tree video. I'm not a fan of 2D but I've learned so much so far.
this is the way I chose to set it up, but I'm glad this video exists anyways because it shows a different approach that may be useful later, for say if you want to guarantee a boss drop goes in your inventory so you don't accidentally walk away without it. Very cool, thanks for the idea!
Hey DevWorm, First thanks for making this series its fun and informative. For the slime loot. I think one could also have the slime's death instantiate a copy of the slime collectible scene. Model it off of the stick resource then the player can pick it up by hitting its collision shape. This might save some time with disabling the slime collectible and its collision shapes. It would also prevent the crash if the player did not enter the collision shape 2d on the slime itself.
just realized it did that... sorry.. your right. It wouldve been so much better to do it that way.
Another tutorial completed. Thanks DevWorm!
thanks brother!! means the world!! you don't have to!! much much love to you! It means the world @Zahardnik3
Youre a great guy bro, once i get my finances back on track i will send you some donations , very informative and i like how you correct your mistakes and explain the logic in a very understandable way for someone like me who is just getting started. ❤
aw dont worry about the money brother! just learn! I'm here to try and teach.. you should save that money and work with a professional developer one-on-one! but it means the world that you find these tutorials helpful! thank you and with your determination to improve you are going to do something truly amazing!
🎉🎉 finally new video !
looking to get really consistent!! thank you so much for watching! Hope it was able to help!
If anybody was having issues with the calculation of the player position in Godot 4.2, this is what worked for me:
position += (player.position - position).normalized() * speed * delta
Idk what was happening, but the enemy seemed to move out of the screen and get stuck
I think you could fix the issue with sprites being blurry so it will look a bit clearer (Texture->filter->change to: nearest)
Thank you once again! Also, some more topic suggestions: how to create cutscenes (character animations, camera movement etc.).
Thanks for the idea! Ill starting working on it right now and Ill try to have the video out within the next 2 days!
I think, and im a bit newbie, that u could simply drop the slime collectable and work with it like the stick, if u pass through u pick it if u don't it disappear after certain time, because we could not want to pick some type of drops... but anyway gj im learning a lot, hope u can keep with the series :)
the audio is perfectly fine
good job!
happy to hear! thank you so much!
Thank you. This fixed my problem.
Hello, Ive just recently got into coding and found this tutorial its super helpful and clear but I noticed there was no damage for the player any suggests on how i might add that thanks ❤
so just like when we created damage for the enemy, it is along the same lines of that! instead you have to put an area2d on the arrow and connect it to check if it enters the player.. and if so then you can change a health variable and function whatever you want to happen when the health is changed or if it equals 0 then to hide the player or play the death function!
thanks for the videos!
you are the best teacher, i want you to play my first ever game i built after learning godot from you
I would be so glad to! Im so happy to hear that Im able to help you out!
@@dev-worm I have uploaded my code in github, is there anyway I can share it to you, you have a discord community?
These are cool but I'd love to see some design patterns applied ❤
thatd be cool! ill look into it right now!
@@dev-worm happy to do some ensemble collaboration if you're interested. Basically we rotate as driver/navigator while we work on a game. 🙂
It's a process we use all day at work, I love it.
thanks broseph!
Can I ask why you chose to use the giant collision shape to find the player as opposed to an onready variable with the get_node() function & an absolute path to the player?
Congratulations on another impeccable video. Now I have a very lively enemy to fight against.
I just have one suggestion and one question.
Suggestion: for future videos, it would be very kind if you tried to keep the script window a little larger to make viewing easier (just a note from a follower with low vision).
Question: when I get the second slime, the label number appears behind the slime icon in the inventory. This only occurs for slimes, the number of apples and sticks appears over the respective icons. Could you instruct me on how to fix this?
Thank you very much
reviewing the previous videos, I realized what might be the source of the problem: in the inv_UI_slot scene I added item_display as a child of CenterContainer and not as a child of Panel. However, when I simply try to pull and release item_display to make it a child of Panel (prior to Label), the game breaks, no longer running in DEBUG. Please, what procedure could I take to fix this without breaking the game?
hmmm.. uh i would have to think that a certain slot is messed up but if you've played the game and picked the items up in different orders and it is still only messing up with slimes then I'm not sure... I'm sorry but id have to look at it. I'm very sorry. if you still haven't got it resolved then try and explain it a little more and maybe I could figure it out by looking at my copy of the game. i'm really sorry and i hope im able to help!
@@dev-worm Many thanks for the reply. There is no need to worry about me in this regard. After you finish your course here, I will redo everything once again, so that I can better understand the processes and concepts in my mind. I have no training in this area and I am learning completely from scratch with some tutorials here on TH-cam. It's worth pointing out that your videos have been the most inspiring and productive for me. Please keep up the great work!
Im sorry to say I am encountering the same issue as I had in the video about creating an enemy as part of your creating an RPG tutorial. The enemy just yeets off into the distance when I enter the detection_area CollisionShape2D. Changing the speed (counterintuitively making the var a bigger number so it walks slower, because of the divide by speed in line 19) it walks right past me on to bigger and greater adventures. I know I haven't even added in the attack animation at this point, but this enemy is just being really passive aggresive about it!
hi. i had this issue, then realised the issue. i had "possition += (player.position - position / speed)" instead of position += (player.position - position) / speed
@@jackygreenhow9889 thanks man
Wondering, why wouldn’t you just create a preload reference to the collectible and then instantiate it, then queue free the actual slime. Would make you not have to deal with all the visible disabling and what not, and would be cleaner down the road like if you wanted to keep track of enemies in the world or collectibles in the world ( like when you want a enemy limit or minimum or when you want a collectible limit ). Then just give the collectible the same script as the stick
Broo it worked in 3d tooooo😊😊😊
so glad to hear!!
I kinda miss you starting off with "HELLO!"
haha.. "HELLO!" Ill make sure to have it in all the next videos.. and then remember that this comment is what revived the HELLO! lol
Wow thanks.
Can you explain about ,Inventory system in Godot 3.5. Because some devices do not run Godot 4
I like your explanation
sorry for the late reply, inventorys are complex and ill try and see what i can do
How would we add damage to the slime so that it can damage the player?
check out the recent "how to create combat system" that is part of the hack'n'slash series that I uploaded about a week ago!! It covers this really well!
@@dev-worm awesome thank you! Keep up the great work, I appreciate all the effort to help us new people!
im having abit of an issue with the collisions . for example, if i stand next to a collider and the slime pushes me, i will just clip through . and the slime just phases through all collisions on the tilemap.
edit: i changed my collider on the player to a capsule shape and that fixed the first problem
edit 2: just added move_and_slide( ) to the physics process and now slime collides .
it is amazing to hear that you were able to figure everything out!! goodjob!
@@dev-worm thanks :) I’ve still got a long way to go before Im out of tutorial hell though lol
@@HighImHorizon How did you manage to keep the enemy from moving when it leaves the detection area? In mine it moves down when I collide with the
Any idea on why I get the error "Invalid set index 'visible' (on base" 'null instance') with value type 'bool'. It doesnt like the code "drop_slime()", and "slime.visible = true". Ive gone back and double checked things but cant seem to find what I missed.
I've had this type of error too and it's just that I misspelled a word in the script, so check the spelling carefully.
I keep getting the same code but instead of "null instance" mine says "staticbody2d"
Edit: My fix ended up being that I spelled Visible as Visable. The person above was right about spelling error. Hope that helps
Sometimes chatgpt can help scan edit your codes. But sometimes it will keep giving a bad solution
Fun fact: you can phase through really narrow places when the slime pushes you to a corridor or to a narrow place.. Try this yourself..
Do the slimes kill you?
Cool man
thanks man!
Bro when are you gonna make the damage that we took from enemy?
that's very easy, you just have hitbox and health box nodes, and add them to the player and enemies, just set up the collision layers correctly so that they interact with each other. (I am using a translator, I speak Spanish). If you like, I'll give you the script for the created nodes.
@@SlowHushHi, would it be possible if i could have those scripts as well? im really lost, thank you
@@Chris-L878 of course, with pleasure, just give me a moment and step script
@@SlowHush me los puedes dar xd? solo de ejemplo ando intentando hacerlo y como que no da
Ich versuche das hier mal auf Deutsch. Ich habe folgende Probleme... 1. Wenn ich in der Range vom Slime einen Stock einsammel verschwindet auch der Slime (Enemy). 2. Seit ich das Arrow system eingebaut habe folgt mir der Slime nicht mehr.
I dont know why my enemy is running away from my character and i follow all your guidelines
I love your work. but I am hitting a snag. the slime is running away from my player. I followed it to the letter, but it seems to run.
man ,are you going to make video about godot 4.2
this uptade awesome has alot of Abbreviation and alot of improvment for both three d and two d
this uptade is very amazing you have to talk about it
bro what if i wanna add this to my platformer ??? i add gravity ?????????
please enlighten me
is there a way to make a reflection shader? without using c#
You should be using velocity and move_and_slide(), not setting positions directly, otherwise they won't respect collision.
yes thats a good point, should've done that instead
Thanks that was helpful
I can’t figure out how to get it to work with that, how did you do it
@@scoringfish1588
# Movement Speed Settings
var speed : float = 0
var speedup : float = 3 # Amount of speed to add while speeding up
var slowdown : float = 3 # Amount of speed to subtract while slowing down
# All movement related functionality goes here
func handle_movement():
var moveDirection = Input.get_vector("Move_Left", "Move_Right", "Move_Up", "Move_Down")
## Player movement handler
## If there is a movement direction increment speed by speedup and clamp to maxSpeed to avoid infinite speed increase
## Else the player is no longer commanding movement and we slow down the speed by slowdown. We increment down speed so
## that if movement is resumed while slowing down it increments up from where it was and not 0
if (moveDirection):
speed = clampf(speed + speedup, 0, statsManager.playerStats.maxSpeed)
velocity = moveDirection * speed
else:
velocity.x = move_toward(velocity.x, 0, slowdown)
velocity.y = move_toward(velocity.y, 0, slowdown)
speed = move_toward(speed, 0, slowdown)
move_and_slide()
I deleted my other comment as it was just me thinking out loud, and this isn't really the place for such a hypothetical discussion.
Now there is a few things I wanted to point out.
Your "dead" variable doesn't need to be initialized in the ready function. It is already initialized when you wrote it out.
On your await function, you can have it wait for the animation_finished signal to trigger. Don't give it the name of the animation, it just doesn't work that way anymore, from my experience.
When doing logical statements, you don't need to write a separate section for the true part. In fact you could have just put that before or after your if block, or use an else statement in your if block.
If !dead:
else:
This is useful if you don't want certain code to execute unless the oposite of your if statement is true. This is just syntax suggestions, your way still works.
To stop your animation in your death function, just call the stop function lol; you don't have to hide it.
yes your right.. i see what your talking about.. thank you for pointing these things out.
I could not find a way to know when the animation finished, so I set my timer to 0.8 seconds. There seems to be a signal but it never fired. AnimationPlayer works great but AnimatedSprite2D doesn't on my game.
Help :(
I'm making a game where I'll have two groups fight each other. I used the same code from the video for the two groups but one's method is enemy and the other knight. However, if characters from the same method collide with each other, they kill each other (lol).
Does anyone have any suggestion as to why that might be? I'm a noob at game dev. Thanks!
maybe you have to write:
func _on_detection_area_body_entered(body):
if body.has_method("player"):
player_in_area = true
player = body
func _on_detection_area_body_exited(body):
if body.has_method("player"):
player_in_area = false
Hello, i have a problem that the enemy only collide with the player, no with the world or with other things.
somebody can help me?
make sure everything is on the same collision layer, and that the enemy's mask is set to see that layer when deciding to collide!
@@dev-worm how can i configure the mask?
please teach how to make game end like when u die or when you win. I have a project that is due soon and i need learn how to do that part lol
Im curious is there a way to make it so the item that drops "slime" just disappears if im not in the detection area like if im far out of the area and end up killing the slime because i have a further camera zoom so i can see more... i kill the slime out of range it drops and crashes i know you maade the detection area to pick up the slime in a larger area but what if we wanted to just kill the slime and move on without picking up the item or just killing it from out of that range it would make the game crash any work around to that?
Hi! use the same code as dropping the apple. Make the slime_collectable scene just like the stick, so it's collectable and change the slime scene to instantiate it into the world, then queue_free the slime monster. Tha6t way you don't have that huge area to deal with and the player gets to collect the slime or not.
You could set a wait timer on the slime_collectable to kill itself after a minute so it's not stuck in the world. :)
nooo don't do it
I am getting an error and a game crash with the line; position += (player.position - position) / speed
Error; Invalid get index 'global' (on base: 'CharacterBody2d (player.gd)').
I've tried using chat gpt to help me out but I still don't understand
Edit;
I went back to one of your old tutorials and added these two lines of code, I had to turn the speed down though;
var direction = (player.position - position).normalized()
position += direction * speed * delta
hey dude can you give me the final code and did it work?
@@Musaf05 Unfortunately I've changed PCs and don't have it anymore. However I found that chat gpt helps out a lot when you need questions answered
thanks dude
This is what I did to make the player have to go collect the dropped loot.
In the slime script do this:
func drop_slime():
slime.visible = true
$slime_collect_area/CollisionShape2D.disabled = false
func slime_collect():
slime.visible = false
player.collect(itemRes)
queue_free()
func _on_slime_collect_area_body_entered(body):
if body.has_method("player"):
player = body
slime_collect()
Shrink down the rat_collect_area>CollisionShape2D so the player has to get to it.
It took me several tries to comment this. Apparently youtube doesn't like ".gd"
yes looks really good!! goodjob Zahardnik3.. im so happy to see you spending so much time trying to learn and get everything right!! it is really amazing to see!
I got an error for trying to collect the item.
Invalid call. Nonexistent function 'collect' in base 'Nil'.
I have no idea why it works for the stick and apple collectables, but not the slime_collectable from the Slime.
It highlights this line of code:
player.collect(item)
It's supposed to work just like the stick (walk over it and you pick it up). The full function code is this:
func slime_collect():
await get_tree().create_timer(1.5).timeout
slime.visible = false
player.collect(item)
queue_free()
---------------------------------------
I basically copied and pasted for the same interactable area body code. I also have this code:
@onready var slime = $slime_collectable
@export var item: InvItem
Can someone help me out, please? idk what to do, the system just doesn't view "collect" as a function. And yet, it views it as a function in my other scripts like for the stick and apple.
it means that your "player" variable is null (probably uninitialized)