This repository has been archived on 2024-07-02. You can view files and clone it, but cannot push or open issues or pull requests.
HoppyEaster/Scripts/WeaponSystem/WeaponController.gd

29 lines
1 KiB
GDScript3
Raw Permalink Normal View History

extends Node2D
@export var projectile_prefab : Resource
@onready var projectilePrefab : PackedScene = load(projectile_prefab.resource_path)
func _process(_delta):
rotate_to_pointer()
if Input.is_action_just_pressed("attack") or Input.is_action_just_pressed("attack_controller"):
2023-04-09 21:22:44 +00:00
spawn_projectile(self.global_position, self.rotation, 350.0, 1)
pass
2023-04-10 20:18:16 +00:00
func get_aim_pos() -> Vector2:
var aim_dir_controller = Input.get_vector("aim_left_controller", "aim_right_controller", "aim_up_controller", "aim_down_controller").normalized()
return get_global_mouse_position() if aim_dir_controller.length() == 0 else self.global_position + aim_dir_controller
func rotate_to_pointer():
2023-04-10 20:18:16 +00:00
look_at(get_aim_pos())
func spawn_projectile(pos : Vector2, dir : float, speed: float, damage : int):
var projectile = projectilePrefab.instantiate()
projectile.global_position = pos
2023-04-09 21:22:44 +00:00
projectile.dir = dir
projectile.speed = speed
projectile.damage = damage
projectile.is_displayed_folded()
get_tree().root.add_child(projectile)
pass