In the first tutorial, dodge thet creep. The enemy used rigidbody2d as a base node. And in the main scene The linear velocity is set Directly. Here is the code.
But when I look at thntuh eo f the rigid body: https://docs.godotengine.org/en/stable/classes/class_rigidbody2d.html
This node implements simulated 2D physics. You do not control a RigidBody2D directly. Instead, you apply forces to it (gravity, impulses, etc.) and the physics simulation calculates the resulting movement based on its mass, friction, and other physical properties.
It''s sid that you canta Control the body directly.
So my question is: Is that tutorial wrong or I just Misunderstanding something?
func _on_MobTimer_timeout():
# Choose a random location on Path2D.
var mob_spawn_location = get_node("MobPath/MobSpawnLocation");
mob_spawn_location.offset = randi()
# Create a Mob instance and add it to the scene.
var mob = mob_scene.instance()
add_child(mob)
# 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 += rand_range(-PI / 4, PI / 4)
mob.rotation = direction
# Choose the velocity.
var velocity = Vector2(rand_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)