Soygoy
I will fight for /anthro/
here u go spas way better system i cooked up just now
Generate the casts on startup or simply make them in the editor, then only check them when you fire and check them once. otherwise do the timer thing I did and pressed if you want rapid fire.
Generate the casts on startup or simply make them in the editor, then only check them when you fire and check them once. otherwise do the timer thing I did and pressed if you want rapid fire.
Code:
extends CharacterBody2D
class_name Player
const SPEED = 300.0
func _ready():
spawn_raycast(5,6)
func _physics_process(delta):
var direction = Input.get_axis("left", "right")
var input_vector = Vector2(
Input.get_action_strength("right") - Input.get_action_strength("left"),
Input.get_action_strength("down") - Input.get_action_strength("up")
)
$Ak47.look_at(get_window().get_mouse_position())
velocity = input_vector * SPEED
move_and_slide()
if Input.is_action_just_pressed("fire"):
for i in $Ak47.get_children():
check_cast(i)
func check_cast(node):
if node is RayCast2D:
if node.get_collider() is Enemy:
node.get_collider().health -= 1
print("Damaged!")
func spawn_raycast(amount=1,range=1):
var flip = 1
for i in amount:
var b = RayCast2D.new()
b.target_position = Vector2(2000,0)
b.position = Vector2(-192,-256)
var variablerange = (90 * flip) / amount / range
b.rotation_degrees = variablerange * i
b.scale = Vector2(8,8)
$Ak47.add_child(b)
flip = -flip