add projectile deflection and move constants to exports

This commit is contained in:
Teatov 2025-02-25 01:08:45 +10:00
parent 20517af12e
commit c0984ce6f8
6 changed files with 56 additions and 32 deletions

View File

@ -54,7 +54,6 @@ bones/45/rotation = Quaternion(-0.0181733, 2.38379e-07, 1.14098e-08, 0.999835)
bones/46/rotation = Quaternion(-1.20807e-07, 0.993087, -0.117383, 7.85287e-07)
bones/48/rotation = Quaternion(-0.034235, -3.57418e-07, 8.86969e-08, 0.999414)
bones/50/rotation = Quaternion(0.403888, -2.98082e-07, -3.85178e-07, 0.914808)
bones/50/scale = Vector3(1, 1, 1)
bones/51/rotation = Quaternion(-0.512846, 3.82068e-07, 4.27952e-07, 0.858481)
bones/51/scale = Vector3(1, 1, 1)
bones/52/rotation = Quaternion(0.0772044, -1.03801e-06, -1.2885e-07, 0.997015)
@ -176,17 +175,17 @@ autoplay = "+idle"
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.9, 0)
shape = SubResource("CylinderShape3D_apl1i")
[node name="AttackArea" type="Area3D" parent="."]
[node name="Attack" type="Area3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
collision_layer = 32
collision_mask = 32
script = ExtResource("3_8pbtx")
_collision_debug_material = ExtResource("4_ll2ct")
[node name="CollisionShape3D" type="CollisionShape3D" parent="AttackArea"]
[node name="AttackShape" type="CollisionShape3D" parent="Attack"]
shape = SubResource("CylinderShape3D_qsqht")
[node name="SwoopMesh" type="MeshInstance3D" parent="AttackArea"]
[node name="SwoopMesh" type="MeshInstance3D" parent="Attack"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -0.0985078, 0, 1, -4.30591e-09, 0, 0, 0)
visible = false
material_override = SubResource("StandardMaterial3D_m1xj5")

View File

@ -61,7 +61,7 @@ func init(children: Array[Node], parent: Node, material: Material) -> void:
func set_visibility(visible: bool) -> void:
is_visible = visible
for node in _mesh_nodes:
node.visible = is_visible
node.visible = is_visible and Debugger.mode == Debugger.Mode.FULL
func _on_debugger_mode_changed(mode: Debugger.Mode) -> void:

View File

@ -10,7 +10,7 @@ var aiming: PlayerAiming = PlayerAiming.new()
var _respawn_point: Vector3
var _debug_collision_shapes := DebugCollisionShapes.new()
@onready var attack: PlayerAttack = $AttackArea
@onready var attack: PlayerAttack = $Attack
func _ready() -> void:

View File

@ -1,7 +1,7 @@
class_name PlayerAiming
extends RefCounted
@export var _controller_aim_offset: float = 20
@export var _controller_aim_offset: float = 15
@export var _vertical_aim_aspect: float = 1.5
var aim_offset: Vector3

View File

@ -3,12 +3,18 @@ extends Area3D
signal attacked
const COOLDOWN_TIME: float = 0.3
const HIT_WINDOW_TIME: float = 0.25
const SWOOP_EFFECT_TIME: float = 0.25
@export_group("Collision")
@export var _collision_debug_material: Material
@export var _attack_max_angle: float = PI / 2
@export var _attack_radius: float = 2
@export_group("Timers")
@export var _cooldown_time: float = 0.3
@export var _hit_window_time: float = 0.25
@export var _swoop_effect_time: float = 0.25
@export_group("Hits")
@export var _hit_projectile_speed: float = 25
var _debug_collision_shapes := DebugCollisionShapes.new()
@ -16,15 +22,22 @@ var _cooldown_timer: float
var _hit_window_timer: float
var _swoop_effect_timer: float
@onready var _swoop_mesh: MeshInstance3D = $SwoopMesh
@onready var _attack_shape_node: CollisionShape3D = $AttackShape
@onready var _swoop_mesh_node: MeshInstance3D = $SwoopMesh
@onready var _attack_shape: CylinderShape3D = _attack_shape_node.shape as CylinderShape3D
@onready var _swoop_mesh: SphereMesh = _swoop_mesh_node.mesh as SphereMesh
func _ready() -> void:
_debug_collision_shapes.init(get_children(), self, _collision_debug_material)
Debugger.add_event("attacked")
attacked.connect(func() -> void: Debugger.event_emitted("attacked", []))
body_entered.connect(_on_body_entered)
position.y = Projectile.HEIGHT
_set_collision_size(_attack_radius)
_debug_collision_shapes.init(get_children(), self, _collision_debug_material)
func _unhandled_input(event: InputEvent) -> void:
@ -44,10 +57,10 @@ func _process(delta: float) -> void:
if _swoop_effect_timer > 0:
_swoop_effect_timer -= delta
(_swoop_mesh.material_override as StandardMaterial3D).albedo_color = Color(
1, 1, 1, _swoop_effect_timer / SWOOP_EFFECT_TIME
(_swoop_mesh_node.material_override as StandardMaterial3D).albedo_color = Color(
1, 1, 1, _swoop_effect_timer / _swoop_effect_time
)
_swoop_mesh.visible = _swoop_effect_timer > 0
_swoop_mesh_node.visible = _swoop_effect_timer > 0
Debugger.text("_cooldown_timer", _cooldown_timer, 2)
Debugger.text("_hit_window_timer", _hit_window_timer, 2)
@ -55,12 +68,18 @@ func _process(delta: float) -> void:
Debugger.vector(
"fghdh",
global_position,
global_position + global_basis.z.rotated(Vector3.UP, _attack_max_angle) * 2
(
global_position
+ global_basis.z.rotated(Vector3.UP, _attack_max_angle) * _attack_radius
)
)
Debugger.vector(
"fghdh2",
global_position,
global_position + global_basis.z.rotated(Vector3.UP, -_attack_max_angle) * 2
(
global_position
+ global_basis.z.rotated(Vector3.UP, -_attack_max_angle) * _attack_radius
)
)
@ -73,9 +92,9 @@ func _attack() -> void:
return
attacked.emit()
_cooldown_timer = COOLDOWN_TIME
_hit_window_timer = HIT_WINDOW_TIME
_swoop_effect_timer = SWOOP_EFFECT_TIME
_cooldown_timer = _cooldown_time
_hit_window_timer = _hit_window_time
_swoop_effect_timer = _swoop_effect_time
_debug_collision_shapes.set_visibility(true)
@ -87,7 +106,13 @@ func _hit_projectile(projectile: Projectile) -> void:
Debugger.vector("ASDSAD2", global_position, global_position + diff)
if angle > _attack_max_angle:
return
projectile.queue_free()
projectile.set_velocity(global_basis.z * _hit_projectile_speed)
func _set_collision_size(radius: float) -> void:
_attack_shape.radius = radius
_swoop_mesh.radius = radius
_swoop_mesh.height = radius
func _on_body_entered(node: Node3D) -> void:

View File

@ -1,12 +1,12 @@
class_name PlayerMovement
extends RefCounted
const MOVE_SPEED: float = 10
const MOVE_ACCELERATION: float = 100
const MOVE_DECELERATION: float = 50
@export var _move_speed: float = 10
@export var _move_acceleration: float = 100
@export var _move_deceleration: float = 50
const FALL_SPEED: float = 20
const FALL_ACCELERATION: float = 25
@export var _fall_speed: float = 20
@export var _fall_acceleration: float = 25
var move_input: Vector2
@ -20,13 +20,13 @@ func lateral_movement(velocity: Vector3, delta: float) -> Vector3:
_move_direction = Vector3(move_input.x, 0, move_input.y).normalized().rotated(
Vector3.UP, Referencer.main_camera.rotation.y
)
var new_velocity := _move_direction * MOVE_SPEED
var new_velocity := _move_direction * _move_speed
new_velocity.y = velocity.y
velocity = velocity.move_toward(new_velocity, MOVE_ACCELERATION * delta)
velocity = velocity.move_toward(new_velocity, _move_acceleration * delta)
else:
var new_velocity := Vector3.ZERO
new_velocity.y = velocity.y
velocity = velocity.move_toward(new_velocity, MOVE_DECELERATION * delta)
velocity = velocity.move_toward(new_velocity, _move_deceleration * delta)
return velocity
@ -34,8 +34,8 @@ func lateral_movement(velocity: Vector3, delta: float) -> Vector3:
func vertical_movement(velocity: Vector3, delta: float, is_on_floor: bool) -> Vector3:
if not is_on_floor:
var new_velocity := velocity
new_velocity.y = -FALL_SPEED
velocity = velocity.move_toward(new_velocity, FALL_ACCELERATION * delta)
new_velocity.y = -_fall_speed
velocity = velocity.move_toward(new_velocity, _fall_acceleration * delta)
else:
velocity.y = 0