godot version 4.3
my code creates a perfect shot the first time but then freezes and slowly moves each time i click
here’s my code
’
extends CharacterBody2D
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
const SPEED = 300.0
var bulletSpeed = 0.01
var bullet = preload(“res://scenes/bullet.tscn”)
var pos = position
var t = 0.0
var allowed = true
var bulletDistance = 3
@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D
@onready var timer: Timer = $Timer
func Shoot():
if allowed == true:
var bulletInstance = bullet.instantiate()
bulletInstance.position = get_global_position()
bulletInstance.rotation = collision_shape_2d.rotation
get_parent().add_child(bulletInstance)
bulletInstance.position = position.lerp(get_global_mouse_position() * bulletDistance, t)
func reload():
allowed = false
timer.start
func _physics_process(delta: float) → void:
t += delta * bulletSpeed
var directionX := Input.get_axis("WalkL", "WalkR")
var directionY := Input.get_axis("WalkU", "WalkD")
var input := Vector2(directionX, directionY)
position += input * SPEED * delta
if input == Vector2(1, 0):
animated_sprite.play("WalkR")
elif input == Vector2(-1, 0):
animated_sprite.play("WalkL")
elif input == Vector2(0, 1):
animated_sprite.play("WalkD")
elif input == Vector2(0,-1):
animated_sprite.play("WalkU")
if input == Vector2(0, 0):
animated_sprite.play("Idle")
if Input.is_action_just_pressed("Shoot"):
Shoot()
move_and_slide()
func _on_timer_reload():
allowed = true
allowed = true
’
thank you in advance