just started learning godot and i am currently following the “your first 2d game” guide and I’ve completed the main game sequence but whenever i try to run it there is a breakpoint on line 46: mob.linear_velocity = velocity.rotated(direction) i thought it may have been a typo so i deleted it and copy-pasted the code from the website and the same thing happened. my mob node type is set to rigged body 2d so it should have “linear_velocity” right? plz help
breakpoints are the red dots in besides the line numbers, inside what we call the “gutter” along with bookmarks, connected signals (green squares), and overriden functions (blue arrows)
If you have a breakpoint in code the debugger will always halt there so you may examine variables and how the code flows. Try pressing F12 to continue execution when you hit a breakpoint or removing it by clicking the red dot again; but a red circle may appear which is as far as I can tell a visual glitch, ignore the red circle.
I think this means you’ve deleted the mob.linear_velocity for just linear_velocity? I believe you had the line correct the first time, unless mob is defined as a player.
If that’s not the case please paste your script with three ticks like so
func _on_mob_timer_timeout():
# Create a new instance of the Mob scene.
var mob = mob_scene.instantiate()
# Choose a random location on Path2D.
var mob_spawn_location = $MobPath/MobSpawnLocation
mob_spawn_location.progress_ratio = randf()
# Set the mob's direction perpendicular to the path direction.
var direction = mob_spawn_location.rotation + PI / 2
# Set the mob's position to a random location.
mob.position = mob_spawn_location.position
# Add some randomness to the direction.
direction += randf_range(-PI / 4, PI / 4)
mob.rotation = direction
# Choose the velocity for the mob.
var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)
# Spawn the mob by adding it to the Main scene.
add_child(mob)
As @gertkeno said, breakpoint is like a bookmark to tell the code execution to stop when reach the designed line, check your code in the line 46 and probably you’ll find a red circle like the one pointed in the image bellow, just left-click this circle and you’ll remove the breakpoint
I would suspect this issue is from giving the “Main” Node a player scene instead of the mob scene in the inspector. The error message sounds like it’s spawning a player.tscn instead of the mob.tscn.
Double check this part of the tutorial
ps the ticks are by the squiggly ~ without shift makes `
func _on_mob_timer_timeout():
# Create a new instance of the Mob scene.
var mob = mob_scene.instantiate()
# Choose a random location on Path2D.
var mob_spawn_location = $MobPath/MobSpawnLocation
mob_spawn_location.progress_ratio = randf()
# Set the mob's direction perpendicular to the path direction.
var direction = mob_spawn_location.rotation + PI / 2
# Set the mob's position to a random location.
mob.position = mob_spawn_location.position
# Add some randomness to the direction.
direction += randf_range(-PI / 4, PI / 4)
mob.rotation = direction
# Choose the velocity for the mob.
var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)
# Spawn the mob by adding it to the Main scene.
add_child(mob)