improve angle dir and add debug lines
This commit is contained in:
parent
50e5421317
commit
58983ecda2
@ -13,6 +13,7 @@ const DEFAULT_COLOR: Color = Color.RED
|
|||||||
var mode: Mode = Mode.PERFORMANCE
|
var mode: Mode = Mode.PERFORMANCE
|
||||||
|
|
||||||
var _vectors_to_draw: Dictionary = {}
|
var _vectors_to_draw: Dictionary = {}
|
||||||
|
var _lines_to_draw: Dictionary = {}
|
||||||
var _markers_to_draw: Dictionary = {}
|
var _markers_to_draw: Dictionary = {}
|
||||||
var _circles_to_draw: Dictionary = {}
|
var _circles_to_draw: Dictionary = {}
|
||||||
var _text_to_draw: Dictionary = {}
|
var _text_to_draw: Dictionary = {}
|
||||||
@ -88,6 +89,15 @@ func vector(
|
|||||||
_vectors_to_draw[key] = {"from": from, "to": to, "color": color, "on": true}
|
_vectors_to_draw[key] = {"from": from, "to": to, "color": color, "on": true}
|
||||||
|
|
||||||
|
|
||||||
|
func line(
|
||||||
|
key: String, from: Vector3, to: Vector3, color: Color = DEFAULT_COLOR
|
||||||
|
) -> void:
|
||||||
|
if not show_debug():
|
||||||
|
return
|
||||||
|
|
||||||
|
_lines_to_draw[key] = {"from": from, "to": to, "color": color, "on": true}
|
||||||
|
|
||||||
|
|
||||||
func marker(
|
func marker(
|
||||||
key: String,
|
key: String,
|
||||||
pos: Vector3,
|
pos: Vector3,
|
||||||
@ -209,6 +219,19 @@ func _draw_vector(from: Vector3, to: Vector3, color: Color) -> void:
|
|||||||
_draw_triangle(end, start.direction_to(end), 5, color)
|
_draw_triangle(end, start.direction_to(end), 5, color)
|
||||||
|
|
||||||
|
|
||||||
|
func _draw_line(from: Vector3, to: Vector3, color: Color) -> void:
|
||||||
|
if (
|
||||||
|
not Referencer.main_camera.is_position_in_frustum(from)
|
||||||
|
and not Referencer.main_camera.is_position_in_frustum(to)
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
|
var start := _unproject(from)
|
||||||
|
var end := _unproject(to)
|
||||||
|
if (start - end).length() > 0:
|
||||||
|
_control.draw_line(start, end, color, LINE_WIDTH)
|
||||||
|
|
||||||
|
|
||||||
func _draw_triangle(
|
func _draw_triangle(
|
||||||
pos: Vector2,
|
pos: Vector2,
|
||||||
dir: Vector2,
|
dir: Vector2,
|
||||||
@ -288,6 +311,15 @@ func _on_control_draw() -> void:
|
|||||||
)
|
)
|
||||||
# v["on"] = false
|
# v["on"] = false
|
||||||
|
|
||||||
|
for v: Dictionary in _lines_to_draw.values():
|
||||||
|
if v["on"]:
|
||||||
|
_draw_line(
|
||||||
|
v["from"] as Vector3,
|
||||||
|
v["to"] as Vector3,
|
||||||
|
v["color"] as Color,
|
||||||
|
)
|
||||||
|
# v["on"] = false
|
||||||
|
|
||||||
for v: Dictionary in _markers_to_draw.values():
|
for v: Dictionary in _markers_to_draw.values():
|
||||||
if v["on"]:
|
if v["on"]:
|
||||||
_draw_marker(
|
_draw_marker(
|
||||||
|
|||||||
@ -7,7 +7,7 @@ enum Side { RIGHT, LEFT }
|
|||||||
|
|
||||||
@export_group("Collision")
|
@export_group("Collision")
|
||||||
@export var _collision_debug_material: Material
|
@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 var _attack_radius: float = 2
|
||||||
|
|
||||||
@export_group("Timers")
|
@export_group("Timers")
|
||||||
@ -16,8 +16,8 @@ enum Side { RIGHT, LEFT }
|
|||||||
@export var _swoop_effect_time: float = 0.25
|
@export var _swoop_effect_time: float = 0.25
|
||||||
|
|
||||||
@export_group("Hits")
|
@export_group("Hits")
|
||||||
@export var _hit_projectile_speed: float = 25
|
@export var _hit_projectile_speed: float = 35
|
||||||
@export var _direction_angles: Dictionary = {PI / 3: 0, 2 * PI / 3: PI / 4, PI: PI / 2}
|
@export var _direction_angles: Dictionary = {-PI / 6: 0, PI / 6: PI / 4, PI: PI / 2}
|
||||||
|
|
||||||
var _side := Side.RIGHT
|
var _side := Side.RIGHT
|
||||||
|
|
||||||
@ -86,6 +86,16 @@ func _process(delta: float) -> void:
|
|||||||
+ global_basis.z.rotated(Vector3.UP, -_attack_max_angle) * _attack_radius
|
+ 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:
|
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:
|
if angle > _attack_max_angle or angle < -_attack_max_angle:
|
||||||
return
|
return
|
||||||
|
|
||||||
var side_angle := (
|
var angle_sign := 1.0 if _side == Side.RIGHT else -1.0
|
||||||
(angle + _attack_max_angle)
|
|
||||||
if _side == Side.RIGHT
|
|
||||||
else (-angle + _attack_max_angle)
|
|
||||||
)
|
|
||||||
Debugger.text("side_angle", rad_to_deg(side_angle), 2)
|
|
||||||
|
|
||||||
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():
|
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)
|
Debugger.text("dir_angle", rad_to_deg(dir_angle), 2)
|
||||||
var new_direction := global_basis.z.rotated(
|
var new_direction := global_basis.z.rotated(
|
||||||
Vector3.UP,
|
Vector3.UP, (_direction_angles[dir_angle] as float) * angle_sign
|
||||||
(
|
)
|
||||||
(_direction_angles[dir_angle] as float)
|
Debugger.vector(
|
||||||
* (1.0 if _side == Side.RIGHT else -1.0)
|
"ASDSAD3",
|
||||||
)
|
projectile.global_position,
|
||||||
|
projectile.global_position + new_direction
|
||||||
)
|
)
|
||||||
projectile.set_velocity(new_direction * _hit_projectile_speed)
|
projectile.set_velocity(new_direction * _hit_projectile_speed)
|
||||||
break
|
break
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user