I am working on making a boss and for it’s only attack I need it to pause a line of code for the attack and then unpause when it is complete here is the line of code here
extends Node2D
const SPEED = 60
var direction = 1
@onready var ray_cast_right: RayCast2D = $RayCastRight @onready var ray_cast_left: RayCast2D = $RayCastLeft @onready var ray_cast_down: RayCast2D = $RayCastDown @onready var ray_cast_up: RayCast2D = $RayCastUp @onready var timer: Timer = $Timer
#Movement
func _process(delta):
if ray_cast_right.is_colliding():
direction = -1
if ray_cast_left.is_colliding():
direction = 1
You got the code correct, I wanted the boss to be flying above the player until the player is directly below the boss, afterwards it slams itself on the floor and it should go back to its original position however when it detects the player it just keeps moving side to side like how it usauly moves
so I would like this line of code paused
#Movement
func _process(delta):
if ray_cast_right.is_colliding():
direction = -1
if ray_cast_left.is_colliding():
direction = 1
position.x += direction * SPEED * delta
Fair enough. Typically the way you do something like that is with a “state machine”, which isn’t as complicated as it sounds:
enum BossState { search, fall, smash, retract }
var state = BossState.search
func _process(delta):
match state:
BossState.search:
if ray_cast_right.is_colliding(): direction = -1
elif ray_cast_left.is_colliding(): direction = 1
if player_is_underneath():
state = BossState.fall
BossState.fall:
# Fall on the player!
BossState.smash:
# Sit on them for a bit!
BossState.retract:
# Go back up!
You could add a variable at the top var player_underneath: bool = false and then set it to true when the ray cast detects the player underneath. Just dont forget to return it to false when player no longer is underneath. Or you could write a function for it. The ““player_is_underneath()” is not found in the base self” means that the function does not exist.