It's hard to tell because I'm only seeing some of the code, but this is quite peculiar. You don't have a Boolean named "motion" do you?
if not, what other parts of the code are you changing/reading motion?
I'm not particularly sure? Boolean is a new term for me so I'm not familar. 😅
But here's all my code for the squirrel if that helps? (Realizing now I probably should've posted this last night, sorry)
extends CharacterBody2D
const NAME = "Squirrel"
@onready var animation_player: AnimationPlayer = $AnimationPlayer
const SPEED = 80
var motion = Vector2()
var UP = Vector2(0,-1)
var direction= -1
var dir = 1
var gravity = 20
var knockback_dir
var knockback
@onready var ray_cast_left: RayCast2D = $RayCastLeft
@onready var ray_cast_right: RayCast2D = $RayCastRight
func _process(delta):
if is_on_floor():
motion.x += SPEED * direction
if ray_cast_right.is_colliding():
direction = -1
if ray_cast_left.is_colliding():
direction = 1
position.x += direction * SPEED * delta
animation_player.play("walk")
func _physics_process(delta):
if knockback == true:
motion.y = -100
motion.x = 100 * knockback_dir
knockback = false
motion = move_and_slide()
func _on_spinner_knockback() -> void:
var player_dir = get_parent().get_node("Spinner").dir
knockback_dir = player_dir
dir = knockback_dir * -1
knockback = true
And here's my spinner which does the knockback (or is supposed to, haha)
extends CharacterBody2D
@export var animation_player: AnimationPlayer
@onready var spin_attack: Area2D = $"spin attack"
@onready var animation_player_2: AnimationPlayer = $AnimationPlayer2
signal knockback
var knockback_dir = Vector2()
var knockback_wait = 50
var dir = 1
func _input(event):
if Input.is_action_just_pressed("spin attack"):
animation_player_2.play("attack")
for body in $"spin attack".get_overlapping_bodies():
if knockback_wait <= 0 and body.get("NAME") == "Squirrel":
emit_signal("knockback")
knockback_wait = 50
knockback_wait -= 1
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
animation_player.play("Spin")
motion = move_and_slide( seems like it's not using a 2d vector but a bool. Stands for boolean which is a value that can be true or false. If motion is a boolean it doesn't have a value motion.y. This would cause motion.y = -100 to cause the error you see. You may need to use velocity.y = -100 instead of motion.y to fix it.
I am not a Godot expert so please take this suggestion with a grain of salt.