I am making a cuphead parody called Ceramic Cranium, and i want to know how the fire rate, i thought of making a timer node that activates as soon as the project starts and loops every 0.2 seconds, and when the timer ends a bullet shoots out of the fingor, but the code wont work, heres the code:
`extends CharacterBody2D
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
@onready var jumpsound: AudioStreamPlayer = $jumpsound
@onready var landsound: AudioStreamPlayer = $landsound
var child_scene = preload("res://assets/scenes/Bullet.tscn")
@onready var fingortip: Marker2D = $Fingortip
@onready var timer: Timer = $Timer
func _on_timer_timeout():
can_shoot = true
var was_in_air = false
var can_shoot = false
const SPEED = 200.0
const JUMP_VELOCITY = -650.0
#lets do something silly
func _physics_process(delta: float) -> void:
if not is_on_floor():
animated_sprite_2d.animation = "Jump"
elif velocity.x > 1 or velocity.x < -1:
animated_sprite_2d.animation = "Walk"
else:
animated_sprite_2d.animation = "Idle"
if not is_on_floor():
velocity += get_gravity() *delta
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
jumpsound.play()
if Input.is_action_pressed("shoot") and can_shoot:
var child = child_scene.instantiate()
get_tree().current_scene.add_child(child)
child.position = fingortip.global_position
timer.start()
Variable to track previous frame state
if not is_on_floor():
was_in_air = true
# move_and_slide() updates is_on_floor()
move_and_slide()
# Check if we just landed
if was_in_air and is_on_floor():
landsound.play()
was_in_air = false
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("left", "right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
if direction == 1.0:
animated_sprite_2d.flip_h = false
elif direction == -1.0:
animated_sprite_2d.flip_h = true
` it has player movement code too but the most important stuff starts at
" if Input.is_action_pressed("shoot") and can_shoot:
var child = child_scene.instantiate()
get_tree().current_scene.add_child(child)
child.position = fingortip.global_position
timer.start()"
can someone please help? thanks!