Invalid set index 'linear_velocity' (on base: 'Node2D') with value of type 'Vector2'

Godot 4

I need help and I’m new to godot

code:

func _ready():
$Area2D.start($Marker2D.position)
$Timer2.start()

func _process(delta):
pass

func _on_timer_2_timeout():
$Timer.start()

func _on_timer_timeout():
var mob = mob_scene.instantiate()
var mob_spawn_location = $Path2D/PathFollow2D
var direction = mob_spawn_location.rotation + PI / 2
mob.position = mob_spawn_location.position
direction += randf_range(-PI / 4, PI / 4)
mob.rotation = direction
var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)
add_child(mob)

Check your mob script, he needs to extends from RigidBody2D, linear_velocity is a RigidBody2D property.

3 Likes

thanks!