getting_started/first_2d_game/05.the_main_game_scene #21
Replies: 77 comments 140 replies
-
|
For the code to actually work, the timer need to be activated through: "func _on_start_timer_timeout():". However, to do so you need to head into the timer node(for the example above, it would be the StartTimer node on the left side of your screen under main in the scene) change tab from inspector to node on the right side of your screen and connect the timeout signal to the main node. Just right click the timeout signal(or double click it), a window will pop up and then left click the main node and press connect. Then do that for all three of the timers(StartTimer, ScoreTimer, MobTimer). (The code didn't work for me until I did this, so I dont know if its my personal issue or not but ill leave the solution here for future viewers) |
Beta Was this translation helpful? Give feedback.
-
|
I'm having problems with the "$Player.start($StartPosition.position)", it gives "Invalid call. Nonexistent function 'start' in base 'Area2D (Player.gd)'? I was thinking it would be more like "$Player.position(...)" but that doesn't work either. |
Beta Was this translation helpful? Give feedback.
-
|
In the testing phase, the creatures don't appear. |
Beta Was this translation helpful? Give feedback.
-
|
C# users must change the connections under the Node tab to C# nomenclature, not the default it provides you. For example: When connecting timeout() from MobTimer, ScoreTimer, StartTimer to Main, it will default to _on_mob_timer_timeout and so on. This needs to be changed to OnMobTimerTimeout(), and so on for the rest. If you are having this issue at this point, you will also need to go back into the Player class and change _on_body_entered to OnBodyEntered() |
Beta Was this translation helpful? Give feedback.
-
This is crazy talk... please maybe an animation or a screenshot of what you're saying here? |
Beta Was this translation helpful? Give feedback.
-
|
Hi, I keep getting the error "Invalid set index 'position' (on base: 'RigidBody2D (mob.gd)') with value of type 'PathFollow2D'. I'm new to Godot so I've got no idea what it means, it causes the game to crash after a couple seconds. Any help would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
-
|
I get this error: "player.gd:10 @ start(): Node not found: "CollisionShape2D" (relative to "/root/Main/Player")", so it doesn't run at all. I double checked and there is indeed a CollisionShape2D node underneath Player... What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
-
|
Hi, newbie here trying to get tutorial working. Godot version 4.3 stable in question. "Script inherits from native type 'RigidBody2D', so it can't be assigned to an object of type: 'AnimatedSprite2D' Tried to find out if anyone else has this problem but no luck. |
Beta Was this translation helpful? Give feedback.
-
|
I was following along pretty well but I´m a bit lost on the _on_mob_timer_timeout function. My questions are:
The rest of the tutorial is amazing. Thank you for the excellent work you put into it. |
Beta Was this translation helpful? Give feedback.
-
|
Something odd with Godot 4.3 on Mac Sequoia (not verified with other platforms). The game starts and plays as expected but the MobTimer stops firing after a random number of mob instances has been created and freed. Eventually the player is left on the screen with no more mob instances and I have to quit the game. I added prints to verify this. |
Beta Was this translation helpful? Give feedback.
-
|
so its not working when i put hide() in the player script on _ready the player never pops back up. When I put new_game() in the _ready function in Main the game crashes and I get 3 errors about unused parameters these include: _process function delta parameter in main.gd Even when new_game() is taken out of the ready function in main.gd the game runs with an empty window just a blank grey screen. Please Help. |
Beta Was this translation helpful? Give feedback.
-
|
I'm confused and stuck at _on_mob_timer_timeout. I copy and pasted the code into the main script but can't see the creatures. Using GDScript. |
Beta Was this translation helpful? Give feedback.
-
|
I had to add
|
Beta Was this translation helpful? Give feedback.
-
|
To elaborate on comments above and in the code on how Imagine that the path drawn is a clockwise race car track where the start/finish line is point 1 (the upper-left corner, where we started drawing the path). When an imaginary race car is on any point of the track, it's pointing in the "forward" direction of the track. As the race car is going along the track, it's progressing along from 0 to 100% of the track... (or a ratio 0.0 to 1.0).
Node ... is setting the race car location to a random amount of "progress" along the track (or lap). Its direction is pointing "forward" for its position on the track. To change the direction to point inward, (which is on the race car's right side), we first rotate it +90 degrees (
|
Beta Was this translation helpful? Give feedback.
-
|
I do not have the 'hit' scene. Even without filter 'hit' I cannot find it anywhere in the scenes. https://ibb.co/vjnyDM2 |
Beta Was this translation helpful? Give feedback.
-
|
Hello Together, i'm trying to recreate the c# part of the tut, but i'm facing the problem that i can't spawn any mobs. I already double checked the code with the repo, but i cant get it to work. Best Regards |
Beta Was this translation helpful? Give feedback.
-
|
If anyone wants the mobs to actually be launched towards the player, you can do this: var mob: RigidBody2D = mob_scene.instantiate()
var player: Area2D = $Player
var mob_spawn_location: PathFollow2D = $MobPath/MobSpawnLocation
mob_spawn_location.progress_ratio = randf()
mob.position = mob_spawn_location.position
var direction: Vector2 = mob.position.direction_to(player.position)
var speed = randf_range(150.0, 250.0)
mob.linear_velocity = direction * speed
mob.rotation = Vector2.RIGHT.angle_to(direction)
add_child(mob) |
Beta Was this translation helpful? Give feedback.
-
|
Question: Is this not supposed to be randomly spawning mobs from all around the edge of the arena? Because if so, it's not doing so; everything's coming from the upper-left corner. |
Beta Was this translation helpful? Give feedback.
-
|
I'm not sure if anyone else also faced this issue but when using
There would be a weird thing where my path2D node and the mobs spawning were out of sync. So no matter what the shape and scale of the Path2D was like, the mobs would continue to spawn in a weird manner nowhere near my path node. I realized after a bit of debugging that you'd actually want the global position if you wanted the mobs to be bound to the Path2D node like I wanted and learnt the very important difference between local and global positions. So it'd be something like:
|
Beta Was this translation helpful? Give feedback.
-
I started the timeout codes and I've been getting these error messages and I don't know what to do |
Beta Was this translation helpful? Give feedback.
-
I have solved my last code problem and now I'm having problems with testing the game. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
Okay, I don't know why but as soon as I launch the game, all I see is one mob falling, then I don't see any other mod, and I don't know why but I guess maybe gravity? I'm stuck and really need help with this one. I'd really appreciate the help. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
Whenever i try to run my code i get an error message |
Beta Was this translation helpful? Give feedback.
-
|
In C# ,for preventing issue, and to have the mobs to spawn i had to change the type for the mob instance: private void OnMobTimerTimeout()
{
RigidBody2D mob = MobScene.Instantiate<RigidBody2D>();
var mobSpawnLocation = GetNode<PathFollow2D>("MobPath/MobSpawnLocation");
mobSpawnLocation.ProgressRatio = GD.Randf();
float direction = mobSpawnLocation.Rotation + Mathf.Pi / 2;
mob.Position = mobSpawnLocation.Position;
direction += (float)GD.RandRange(-Mathf.Pi / 4, Mathf.Pi / 4);
mob.Rotation = direction;
var velocity = new Vector2((float)GD.RandRange(150.0, 250.0), 0);
mob.LinearVelocity = velocity.Rotated(direction);
AddChild(mob);
} |
Beta Was this translation helpful? Give feedback.
-
|
Hi! |
Beta Was this translation helpful? Give feedback.
-
|
For anyone that enforces Unsafe Property Access or Unsafe Method Access you'll get an error when trying to access the Player scene that the start() function doesn't exist. You need to define a class for the player. I did this by just adding it under extends like so: extends Area2D
class_name AlienPlayerThen when you reference it in your main script like so: @onready var player: AlienPlayer = $Player |
Beta Was this translation helpful? Give feedback.
-
|
I have two questions, firstly, why do we set the mob_scene variable as an export to the global UI and then call the mob scene in the UI rather than setting the mob scene as a child of main and then using get_node to call it and then instantiate it? |
Beta Was this translation helpful? Give feedback.
-
|
Guys, please check the spellings of the node names you are giving , otherwise it will give null error. |
Beta Was this translation helpful? Give feedback.









Uh oh!
There was an error while loading. Please reload this page.
-
getting_started/first_2d_game/05.the_main_game_scene
Now it's time to bring everything we did together into a playable game scene. Create a new scene and add a Node named Main. (The reason we are using Node instead of Node2D is because this node will...
https://docs.godotengine.org/en/latest/getting_started/first_2d_game/05.the_main_game_scene.html
Beta Was this translation helpful? Give feedback.
All reactions