|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
godot再次求助- extends Area2D
- @onready var launcher: CharacterBody2D = get_node("/root/Main/Player")
- @onready var speed : float = launcher.bullet_speed
- @onready var rate : float = launcher.bullet_rate
- @onready var max_distance : float= launcher.bullet_distance
- @onready var attack : int = launcher.attack
- var bullets = []
- var distances = []
- var scene = preload("res://bullet/bullet.tscn")
- var is_firing := false
- func _process(delta: float) -> void:
- for each in bullets:
- var direction = Vector2.UP.rotated(each[0].global_rotation).normalized()
- var velocity = direction * speed * delta
- each[0].global_position += velocity
-
- # 判断是否到了最大距离
- if each[1].distance_to(each[0].global_position) >= max_distance:
- each[0].queue_free()
- bullets.erase(each)
-
- func _input(event: InputEvent) -> void:
- if event.is_action_pressed("fire"):
- await _fire_bullet()
-
- func _fire_bullet() -> void:
- if is_firing:
- return
-
- is_firing = true
- _create_bullet()
- await get_tree().create_timer(rate).timeout
- is_firing = false
- func _create_bullet() -> void:
- var ins = scene.instantiate()
- self.add_child(ins)
- ins.global_position = launcher.global_position
- ins.global_rotation = launcher.global_rotation
-
- var list = [ins, ins.global_position]
- bullets.append(list)
复制代码
老是冒出几个飞得很快的子弹 |
|