add hitting angles from left and right

This commit is contained in:
Teatov 2025-02-25 01:47:05 +10:00
parent c0984ce6f8
commit 50e5421317
3 changed files with 51 additions and 10 deletions

View File

@ -33,8 +33,8 @@ func _physics_process(delta: float) -> void:
if not is_multiplayer_authority(): if not is_multiplayer_authority():
return return
velocity = movement.lateral_movement(velocity, delta) var can_move := not attack.is_hitting()
velocity = movement.vertical_movement(velocity, delta, is_on_floor()) velocity = movement.movement(velocity, delta, is_on_floor(), can_move)
move_and_slide() move_and_slide()

View File

@ -3,6 +3,8 @@ extends Area3D
signal attacked signal attacked
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 = PI / 2
@ -10,11 +12,14 @@ signal attacked
@export_group("Timers") @export_group("Timers")
@export var _cooldown_time: float = 0.3 @export var _cooldown_time: float = 0.3
@export var _hit_window_time: float = 0.25 @export var _hit_window_time: float = 0.15
@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 = 25
@export var _direction_angles: Dictionary = {PI / 3: 0, 2 * PI / 3: PI / 4, PI: PI / 2}
var _side := Side.RIGHT
var _debug_collision_shapes := DebugCollisionShapes.new() var _debug_collision_shapes := DebugCollisionShapes.new()
@ -84,7 +89,11 @@ func _process(delta: float) -> void:
func _physics_process(_delta: float) -> void: func _physics_process(_delta: float) -> void:
monitoring = Input.is_action_just_pressed("attack") monitoring = _hit_window_timer > 0
func is_hitting() -> bool:
return _hit_window_timer > 0
func _attack() -> void: func _attack() -> void:
@ -96,17 +105,41 @@ func _attack() -> void:
_hit_window_timer = _hit_window_time _hit_window_timer = _hit_window_time
_swoop_effect_timer = _swoop_effect_time _swoop_effect_timer = _swoop_effect_time
_debug_collision_shapes.set_visibility(true) _debug_collision_shapes.set_visibility(true)
_side = Side.LEFT if _side == Side.RIGHT else Side.RIGHT
func _hit_projectile(projectile: Projectile) -> void: func _hit_projectile(projectile: Projectile) -> void:
var diff := projectile.global_position - global_position var diff := projectile.global_position - global_position
diff.y = 0 diff.y = 0
var angle := global_basis.z.angle_to(diff) var angle := global_basis.z.signed_angle_to(diff, Vector3.UP)
Debugger.vector("ASDSAD", global_position, global_position + global_basis.z) Debugger.vector("ASDSAD", global_position, global_position + global_basis.z)
Debugger.vector("ASDSAD2", global_position, global_position + diff) Debugger.vector("ASDSAD2", global_position, global_position + diff)
if angle > _attack_max_angle: Debugger.text("angle", rad_to_deg(angle), 2)
if angle > _attack_max_angle or angle < -_attack_max_angle:
return return
projectile.set_velocity(global_basis.z * _hit_projectile_speed)
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 prev_dir_angle: float = 0
for dir_angle: float in _direction_angles.keys():
if side_angle > prev_dir_angle and side_angle <= dir_angle:
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)
)
)
projectile.set_velocity(new_direction * _hit_projectile_speed)
break
prev_dir_angle = dir_angle
func _set_collision_size(radius: float) -> void: func _set_collision_size(radius: float) -> void:

View File

@ -13,10 +13,18 @@ var move_input: Vector2
var _move_direction: Vector3 var _move_direction: Vector3
func lateral_movement(velocity: Vector3, delta: float) -> Vector3: func movement(
velocity: Vector3, delta: float, is_on_floor: bool, can_move: bool
) -> Vector3:
velocity = _lateral_movement(velocity, delta, can_move)
velocity = _vertical_movement(velocity, delta, is_on_floor)
return velocity
func _lateral_movement(velocity: Vector3, delta: float, can_move: bool) -> Vector3:
move_input = Input.get_vector("move_left", "move_right", "move_up", "move_down") move_input = Input.get_vector("move_left", "move_right", "move_up", "move_down")
if move_input.length() > 0: if move_input.length() > 0 and can_move:
_move_direction = Vector3(move_input.x, 0, move_input.y).normalized().rotated( _move_direction = Vector3(move_input.x, 0, move_input.y).normalized().rotated(
Vector3.UP, Referencer.main_camera.rotation.y Vector3.UP, Referencer.main_camera.rotation.y
) )
@ -31,7 +39,7 @@ func lateral_movement(velocity: Vector3, delta: float) -> Vector3:
return velocity return velocity
func vertical_movement(velocity: Vector3, delta: float, is_on_floor: bool) -> Vector3: func _vertical_movement(velocity: Vector3, delta: float, is_on_floor: bool) -> Vector3:
if not is_on_floor: if not is_on_floor:
var new_velocity := velocity var new_velocity := velocity
new_velocity.y = -_fall_speed new_velocity.y = -_fall_speed