getting_started/first_3d_game/05.spawning_mobs #59
Replies: 22 comments 33 replies
-
Also worth mentioning that as per the 2D Tutorial, you can grab references to child nodes using $ also. I like how both tutorials show to do this two different ways (though using |
Beta Was this translation helpful? Give feedback.
-
If the mob is not spawning you'll probably have to get the Timer Node on the Main Script public override void _Ready(){
var mobTimer = GetNode<Timer>("MobTimer");
mobTimer.Timeout += OnMobTimerTimeout;
} |
Beta Was this translation helpful? Give feedback.
-
For some reason, my mobs are sometimes spawning with an X rotation, making their tails clip into the ground. It seems to happen during the |
Beta Was this translation helpful? Give feedback.
-
hello, I keep getting the red text saying "Cannot call method 'instantiate' on a null value" whenever I press F6, it directed me to line 7 of the code but im not sure what is wrong with it, I even copy pasted the exact code from the tutorial but i'm still getting the same issue. There is a yellow line pointing towards line 7 where I've put: var mob = mob_scene.instantiate() Is there supposed to be something else in this line? The code I used: extends Node
@export var mob_scene: PackedScene
func _on_mob_timer_timeout():
# Create a new instance of the Mob scene.
var mob = mob_scene.instantiate()
# Choose a random location on the SpawnPath.
# We store the reference to the SpawnLocation node.
var mob_spawn_location = get_node("SpawnPath/SpawnLocation")
# And give it a random offset.
mob_spawn_location.progress_ratio = randf()
var player_position = $Player.position
mob.initialize(mob_spawn_location.position, player_position)
#Spawn the mob by adding it to the main scene.
add_child(mob) Thanks |
Beta Was this translation helpful? Give feedback.
-
I fixed the error by declaring the variables with type. It is also good style to do this. The framework tells you when you are overriding an existing variable or function. My function looks like this: func _on_mob_timer_timeout() -> void:
# Create the variables
var mob: CharacterBody3D
var mob_spawn_location: PathFollow3D
var player_position: Vector3
# Create a new instance of the Mob scene.
mob = mob_scene.instantiate()
# Choose a random location on the SpawnPath.
# We store the reference to the SpawnLocation node.
mob_spawn_location = $SpawnPath/Spawnlocation
# And give it a random offset.
mob_spawn_location.progress_ratio = randf()
player_position = $Player.position
mob.initialize(mob_spawn_location.position, player_position)
# Spawn the mob by adding it to the Main scene.
add_child(mob)
Maybe this is interesting for someone. |
Beta Was this translation helpful? Give feedback.
-
It should be a MeshInstance3D instead of MeshInstance. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone!!! I fixed it this way: I corrected it to: Strange, according to the tutorial the hierarchy is specified as SpawnLocation child node SpawnPath, why is it the other way round in the code? |
Beta Was this translation helpful? Give feedback.
-
Why does when i press F6 my game starts but there is always a mob model that does not move under the player model? |
Beta Was this translation helpful? Give feedback.
-
I have a problem on the part where you place the cylinders, my view of the camera can see the edge of the floor, so if I fill the floor and place the cylinders, the cylinders are so far apart compare to the image above |
Beta Was this translation helpful? Give feedback.
-
Godot 4 doesn't seem to have the option to toggle the visibility of a regular Node (unless im doing something wrong) I can see the eye icon next to all four MeshInstance3Ds, but not next to the |
Beta Was this translation helpful? Give feedback.
-
I've ran into a snag, My mobs aren't moving around. they're spawning but static, they also seem to be facing towards the same location on spawn. I've switched the code i writ with the provided code. i assumed it was something to do with creating the SpawnPath and SpawnLocation but have recreacted to no avail. if more information is required i will provide. Thanks for reading :) |
Beta Was this translation helpful? Give feedback.
-
The mobs aren't spawning for me |
Beta Was this translation helpful? Give feedback.
-
The mobs and the player in the screenshots in this tutorial has a glazed, shiny look. But when I run the program, the mobs and the player have this matted / satin spray-painted look. XD |
Beta Was this translation helpful? Give feedback.
-
Hello everyone, my mobs are spawning above the player. I don't have any idea why this is happening. How can i fix it? |
Beta Was this translation helpful? Give feedback.
-
Hello, i'm getting this error and i have no idea what's wrong: Invalid type in function 'look_at_from_position' in base 'CharacterBody3D (mob.gd)'. Cannot convert argument 1 from Object to Vector3. |
Beta Was this translation helpful? Give feedback.
-
The mobs wasn't appearing so i just named the function "_on_mob_timer_timeout()" instead of "OnMobTimerTimeout()" like in the C# example. |
Beta Was this translation helpful? Give feedback.
-
I noticed that placing the points to create SpawnPath in the editor is difficult and any variance in y axis for the points will cause the Mobs to sometimes generate with a y "tilt" pointing either slightly up or slightly down as they target the player. This is exacerbated when the player jumps and, while in the air, a new mob spawns. I ended up "normalizing" the y plane to 0.5 for both spawn location as well as the player's location when sampled for spawning a mob to keep them firmly on the xz plane, but a more elegant/robust solution in the instructions would be appreciated. |
Beta Was this translation helpful? Give feedback.
-
Am I supposed to move the mesh instance or the cylinder node containing it while scoping out the path? I find it more productive to ask than waste a lot of time. I'm old for this. I played Pong when it was breathtakingly cutting edge. |
Beta Was this translation helpful? Give feedback.
-
i need some help its giving me error in the player position line saying there is no player the tutorial does say something about player in the main scene but idk how to fix this can anyone help me out on this? |
Beta Was this translation helpful? Give feedback.
-
Hey team, Im a noob and still trying to navagate through this. Im stuck due to this error message "script inherits from native type characterbody3d so it cant be assigned to an object type: Node 3d" Dose anyone have a solution for this? Thank you |
Beta Was this translation helpful? Give feedback.
-
Is there a way of having the editor show a hint for the custom functions we add in the scripts attached to our nodes (sorry if I mess up terminology, I'm still very new to Godot)? For example, we give the Mob node in mob.tcsn an I thought providing a type when declaring the variable might help, but |
Beta Was this translation helpful? Give feedback.
-
Hello, I followed this section of this tutorial but when I try to test I'm facing the following error:
Any ideas of what can cause this error ? Thanks |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
getting_started/first_3d_game/05.spawning_mobs
In this part, we're going to spawn monsters along a path randomly. By the end, you will have monsters roaming the game board. image0 Double-click on main.tscn in the FileSystem dock to open the Mai...
https://docs.godotengine.org/en/stable/getting_started/first_3d_game/05.spawning_mobs.html
Beta Was this translation helpful? Give feedback.
All reactions