I'm following the 3D tutorial Squash the Creeps using Godot 4.1.2 on Ubuntu 22.04. At some point, the mobs are instantiated but they are not moving. I'm sure the mob scene is called from the main scene since the mobs appear. The player can move as intended too. I believe the _physics_process function from the mob script, and therefore its move_and_slide() function, is actually never called (print("Physics process in mob is called!") is not appearing using the code below, but the prints in initialize work).
The code I'm using comes from the tutorial. For the main scene, this is
extends Node
@export var mob_scene: PackedScene
func _on_mob_timer_timeout():
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)
and for the mob script
extends CharacterBody3D
@export var min_speed = 10
@export var max_speed = 18
func _physics_process(_delta):
print("Physics process in mob is called!")
print(is_on_floor()) #Just a test to see if the mob touches the floor
move_and_slide()
func initialize(start_position, player_position):
print("Start_position,player_position",start_position, player_position)
look_at_from_position(start_position, player_position, Vector3.UP)
# Rotate this mob randomly within range of -90 and +90 degrees,
# so that it doesn't move directly towards the player.
rotate_y(randf_range(-PI / 4, PI / 4))
# We calculate a random speed (integer)
var random_speed = randi_range(min_speed, max_speed)
print("Random speed ",random_speed)
# We calculate a forward velocity that represents the speed.
velocity = Vector3.FORWARD * random_speed
print("Velocity ",velocity)
# We then rotate the velocity vector based on the mob's Y rotation
# in order to move in the direction the mob is looking.
velocity = velocity.rotated(Vector3.FORWARD, rotation.y)
print("Velocity final ",velocity)
print("Position of the mob ", position)