Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

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")

(1 edit)

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.

(+1)

Yeah no worries!! 

I'll give this a try later tonight and let you know if it works out! Thank you! ๐Ÿ˜„

just looked it up, move and slide returns if there was a collision (true or false)
try calling the function without the "motion ="

(+2)

This did fix the error!... but my knockback still isn't working for some reason... Lol.

(+1)

you are calling move and slide only once (in the knockback function), but you need to call it every frame for it to continuously update

like

func _physics_process(delta):
    move_and_slide()

Glad that helped. I think SimulatedGravity has your next step. You need to process the action as long as you have velocity to keep it animating. Consider friction or something similar to slow it over time or it will just continue to be blown away.