improve angle dir and add debug lines

This commit is contained in:
2025-02-25 02:12:26 +10:00
parent 50e5421317
commit 58983ecda2
2 changed files with 59 additions and 16 deletions

View File

@@ -7,7 +7,7 @@ enum Side { RIGHT, LEFT }
@export_group("Collision")
@export var _collision_debug_material: Material
@export var _attack_max_angle: float = PI / 2
@export var _attack_max_angle: float = 2 * PI / 3
@export var _attack_radius: float = 2
@export_group("Timers")
@@ -16,8 +16,8 @@ enum Side { RIGHT, LEFT }
@export var _swoop_effect_time: float = 0.25
@export_group("Hits")
@export var _hit_projectile_speed: float = 25
@export var _direction_angles: Dictionary = {PI / 3: 0, 2 * PI / 3: PI / 4, PI: PI / 2}
@export var _hit_projectile_speed: float = 35
@export var _direction_angles: Dictionary = {-PI / 6: 0, PI / 6: PI / 4, PI: PI / 2}
var _side := Side.RIGHT
@@ -86,6 +86,16 @@ func _process(delta: float) -> void:
+ global_basis.z.rotated(Vector3.UP, -_attack_max_angle) * _attack_radius
)
)
for dir_angle: float in _direction_angles:
Debugger.line(
"fghdh3" + str(dir_angle),
global_position,
(
global_position
+ global_basis.z.rotated(Vector3.UP, dir_angle) * _attack_radius
),
Color.BLUE
)
func _physics_process(_delta: float) -> void:
@@ -118,23 +128,24 @@ func _hit_projectile(projectile: Projectile) -> void:
if angle > _attack_max_angle or angle < -_attack_max_angle:
return
var side_angle := (
(angle + _attack_max_angle)
if _side == Side.RIGHT
else (-angle + _attack_max_angle)
)
Debugger.text("side_angle", rad_to_deg(side_angle), 2)
var angle_sign := 1.0 if _side == Side.RIGHT else -1.0
var prev_dir_angle: float = 0
var angle_signed := angle * angle_sign
Debugger.text("side", Side.find_key(_side), 2)
Debugger.text("angle_signed", rad_to_deg(angle_signed), 2)
var prev_dir_angle: float = -_attack_max_angle
for dir_angle: float in _direction_angles.keys():
if side_angle > prev_dir_angle and side_angle <= dir_angle:
if angle_signed > prev_dir_angle and angle_signed <= dir_angle:
Debugger.text("prev_dir_angle", rad_to_deg(prev_dir_angle), 2)
Debugger.text("dir_angle", rad_to_deg(dir_angle), 2)
var new_direction := global_basis.z.rotated(
Vector3.UP,
(
(_direction_angles[dir_angle] as float)
* (1.0 if _side == Side.RIGHT else -1.0)
)
Vector3.UP, (_direction_angles[dir_angle] as float) * angle_sign
)
Debugger.vector(
"ASDSAD3",
projectile.global_position,
projectile.global_position + new_direction
)
projectile.set_velocity(new_direction * _hit_projectile_speed)
break