AhmedFebruary2025/ahmedgg/bullet.gd

24 lines
467 B
GDScript

class_name Bullet extends Area2D
@onready var bulletGraphic: Sprite2D = $Sprite2D
var speed = 500
signal hit(bullet, body)
func setSpeed(value):
speed = value
if speed <0:
bulletGraphic.flip_h = true
if speed>0:
bulletGraphic.flip_h = false
#animation
func _physics_process(delta: float) -> void:
position +=transform.x*speed*delta
func _on_body_entered(body: Node2D) -> void:
print ("bullet collision")
if not body is Player:
hit.emit(self, body)