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

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By baz1975

This line in the tutorial for making a new 2D game on your Godot Documentation webpage is not working:
var velocity = Vector2(rand_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction) *

I’m not sure how to fix it. Any help would be appreciated.

:bust_in_silhouette: Reply From: jgodfrey

I think the problem is with your Mob scene. Its root node should be of type Rigidbody2D but, according to the error, it’s a Node2D.

If that’s the case, you can right-click the root node in the Mob scene and use Change Type to set it to Rigidbody2D. Also, if the node type was wrong, you’ll likely need to change the top line of the Mob script from:

extends Node2D


extends RigidBody2D

Thank you. You saved me a lot of headache.

baz1975 | 2023-01-10 17:03

1 Like