getting_started/first_2d_game/04.creating_the_enemy #82
Replies: 27 comments 32 replies
-
C# users must change the connections under the Node tab to C# nomenclature, not the default it provides you. Change _on_visible_on_screen_notifier_2d_screen_exited to OnVisibleOnScreenNotifier2DScreenExited, or, if you've already created the script as guided, you can select the Pick button to the right of the text field when editing the connection, and then select the appropriate method. |
Beta Was this translation helpful? Give feedback.
-
I need help with the enemy animations. |
Beta Was this translation helpful? Give feedback.
-
When you say to "To align the shape with the image", not all sprites have the same size, but we only use 1 AnimatedSprite2D, shouldn't we use one for each ? |
Beta Was this translation helpful? Give feedback.
-
What does the Collision Mask mean? It just says to uncheck the 1 but it feels really random with no explanation |
Beta Was this translation helpful? Give feedback.
-
Make sure to set the collision shape 2D on the mob or else it will not work when it hits the player. I know this is obvious, but I forgot LOL. |
Beta Was this translation helpful? Give feedback.
-
This has me going :hmm: I know you just explained how to do this in the previous section, but maybe you could give alittle more context? |
Beta Was this translation helpful? Give feedback.
-
Why do you use RigidBody2D as the root node of mob, but use Area2D as the root node of player? Are there any differences? Thanks for any responses. |
Beta Was this translation helpful? Give feedback.
-
In these examples I often see repeated uses of In real projects, is it worth it to assign the node to a variable and reuse that instead of repeatedly calling |
Beta Was this translation helpful? Give feedback.
-
I set my gravity scale to 0 on the rigid body and the enemy still falls and i cant seem to figure out why |
Beta Was this translation helpful? Give feedback.
-
The _on_body_entered function is never being called. I followed this tutorial closely.
I set "Debug > Visible collision shapes" so that I can clearly see the shapes overlapping. Any other ideas to debug this issue? Thanks. |
Beta Was this translation helpful? Give feedback.
-
When I type extends Rigidbody2D in mob, if it already has extends Area2D then it generates an error, but if I change the extends Area2D to Rigidbody2D it makes the same change also in player. I do not know how to proceed. |
Beta Was this translation helpful? Give feedback.
-
Keep in mind that the OnVisibleOnScreenNotifier2DScreenExited method has to be public for the Pick button to work on the Connect dialog. If you have it Private, like in the Tutorial above, it won't be detected. |
Beta Was this translation helpful? Give feedback.
-
For some reason the enemy Mobs collide and bounce off each other's Mobs. How can the Mobs fly around without crashing next to the other ones? Not sure where I've caused them to collide. |
Beta Was this translation helpful? Give feedback.
-
In CollisionObject2D we disable "Mask 1", so that the enemies can go through one another, correct? For example something like _on_body_entered.mask_1() ? |
Beta Was this translation helpful? Give feedback.
-
I tried to switch up things a bit, but have a problem... |
Beta Was this translation helpful? Give feedback.
-
Note that the "%" means "modulo operator" (and not a specific/weird keyword thing)
So, you can read this as:
You could use this as an equivalent without using modulo: |
Beta Was this translation helpful? Give feedback.
-
The demo project and the tutorial has different code and it should be synced. In the tutorial: func _ready() -> void:
var mob_types = $AnimatedSprite2D.sprite_frames.get_animation_names()
$AnimatedSprite2D.play(mob_types[randi() % mob_types.size()]) Where the demo project's mob.gd is: func _ready():
$AnimatedSprite2D.play()
var mob_types = Array($AnimatedSprite2D.sprite_frames.get_animation_names())
$AnimatedSprite2D.animation = mob_types.pick_random()
|
Beta Was this translation helpful? Give feedback.
-
A .gif showing how the mobs should behave at the end of this part of the tutorial would be super helpful. When I run this script, I have one mob in the upper left corner of the screen doing it's animation. I'm not sure if this is correct or not. |
Beta Was this translation helpful? Give feedback.
-
This took me a little bit to figure out because I had already named RigidBody2D to Mob. |
Beta Was this translation helpful? Give feedback.
-
I'm running into a roadblock with this tutorial in Godot 4.3. I'm actually on the following step of the tutorial (The main game scene), and my game is crashing every time I run it with the error: "Invalid call. Nonexistent function 'get_animation_names' in base 'AnimatedSprite2D'." The mobs do not spawn along my path or anywhere else, and the game just crashes. Is there a new getter I need to make this work? |
Beta Was this translation helpful? Give feedback.
-
extends RigidBody2D
func _ready() -> void:
var mob_types = $AnimatedSprite2D.sprite_frames.get_animation_names()
$AnimatedSprite2D.play(mob_types[randi() % mob_types.size()])
func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
$CollisionShape2D.set_deferred("disabled", true)
queue_free() is it neccesary use set_deffered here? |
Beta Was this translation helpful? Give feedback.
-
For anyone else looking for why the animation isn't playing: You need to add
under
It should look like:
|
Beta Was this translation helpful? Give feedback.
-
I feel like this guide is missing a step to resize the VisibleOnScreenNotifier2D node. When I created it, it was like a 10x10 rectangle which caused the the mobs to despawn at the edge of the screen while still visible. The node rect has to be resized to include the entire mob sprite. |
Beta Was this translation helpful? Give feedback.
-
Shouldn't we add $AnimatedSprite2D.play() here? Without this the mob is not animating in my Main scene. func _ready(): |
Beta Was this translation helpful? Give feedback.
-
I'm trying to set up my mob nodes, and to make the children unselectable (per "Don't forget to set the children so they can't be selected, like you did with the Player scene."), but I don't have that icon (or any icons) showing up beside the mob root node. I didn't have a problem with setting up the Player scene. I can't figure out how to get that icon to show up, or to find it in options somewhere. |
Beta Was this translation helpful? Give feedback.
-
Hmm, the CollisionShape2D can be aligned nicely with the swim and walk sprite animations, but not with the fly one... I guess since this is an earlier tutorial, I shouldn't worry about accuracy too much? |
Beta Was this translation helpful? Give feedback.
-
So my mob is using the animation in the game, but the mob is just flying across the screen. What's up with that? The mob is not going through it's animation cycle properly and as soon as it enters the area it instantly falls and does not go across the screen as intended. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
getting_started/first_2d_game/04.creating_the_enemy
Now it's time to make the enemies our player will have to dodge. Their behavior will not be very complex: mobs will spawn randomly at the edges of the screen, choose a random direction, and move in...
https://docs.godotengine.org/en/stable/getting_started/first_2d_game/04.creating_the_enemy.html
Beta Was this translation helpful? Give feedback.
All reactions