Compare commits

..

3 Commits

5 changed files with 50 additions and 27 deletions

View File

@ -7,14 +7,27 @@ var target: Targetable = null
@export var charge_time := 1.7 @export var charge_time := 1.7
@export var min_charge := 0.2 @export var min_charge := 0.2
var camera_tweening = false
func _ready(): func _ready():
set_target(initial_target) set_target(initial_target, false)
ControllerEventBus.billiard_touched_billiard.connect(_on_billiard_touched_billiard)
func _on_billiard_touched_billiard(who: Billiard, touched: Billiard):
var who_target = Targetable.is_targetable(who)
if who_target != target or who.can_hit:
return
set_target(touched)
ControllerEventBus.new_target.emit(touched)
func get_charge(): func get_charge():
return %radial_ui.charge_amount return %radial_ui.charge_amount
func _input(event): func _input(event):
var billiard := target.get_billiard() var billiard := target.get_billiard()
if camera_tweening:
return
if event is InputEventMouseMotion and MouseControl.mouse_is_locked() and get_charge() == 0.0 : if event is InputEventMouseMotion and MouseControl.mouse_is_locked() and get_charge() == 0.0 :
rotate_view(event.relative*sensitivity) rotate_view(event.relative*sensitivity)
if event.is_action_released("charge") and not billiard.can_hit and charge_tween != null: if event.is_action_released("charge") and not billiard.can_hit and charge_tween != null:
@ -22,10 +35,19 @@ func _input(event):
if event.is_action_pressed("charge") and billiard.can_hit and charge_tween == null: if event.is_action_pressed("charge") and billiard.can_hit and charge_tween == null:
charge(event.get_action_strength("charge")) charge(event.get_action_strength("charge"))
func _process(_delta): func _process(delta):
transform.origin = target.global_position transform.origin = target.global_position
camera.global_position = %camera_spot.global_position %camera_spot.look_at(target.global_position)
camera.look_at(target.global_position) if not camera_tweening:
camera.global_transform = %camera_spot.global_transform
else:
camera.global_position = lerp(camera.global_position, %camera_spot.global_position, 0.00000000001)
camera.global_rotation = lerp(camera.global_rotation, %camera_spot.global_rotation, 0.00000000001)
var epsilon: float = 0.0001
if (camera.global_position - %camera_spot.global_position).length() <= epsilon and (camera.global_rotation - %camera_spot.global_rotation).length() <= epsilon:
camera_tweening = false
if get_charge() >= 1.0: if get_charge() >= 1.0:
cancel_charge() cancel_charge()
@ -46,6 +68,7 @@ func release():
%ChargeReleaseSound.play() %ChargeReleaseSound.play()
var billiard := target.get_billiard() var billiard := target.get_billiard()
billiard.hit((target.global_position - %camera_spot.global_position).normalized(), get_charge()) billiard.hit((target.global_position - %camera_spot.global_position).normalized(), get_charge())
%radial_ui.set_charge(0.0) %radial_ui.set_charge(0.0)
%ChargeSound.stop() %ChargeSound.stop()
if charge_tween != null: if charge_tween != null:
@ -67,8 +90,13 @@ func rotate_view(amount: Vector2):
%rotate_helper.rotate_z(amount.y) %rotate_helper.rotate_z(amount.y)
%rotate_helper.rotation_degrees.z = clampf(%rotate_helper.rotation_degrees.z, -77, 77) %rotate_helper.rotation_degrees.z = clampf(%rotate_helper.rotation_degrees.z, -77, 77)
func set_target(node: Node3D):
func set_target(node: Node3D, should_create_tween=true):
camera_tweening = should_create_tween
var ntarget = Targetable.is_targetable(node) var ntarget = Targetable.is_targetable(node)
var billiard = ntarget.get_billiard()
billiard.can_hit = true
if ntarget == null: if ntarget == null:
push_error("Node is node targetable", node) push_error("Node is node targetable", node)
return return

View File

@ -35,8 +35,6 @@ func change_all_materials(mesh: MeshInstance3D):
layer1.render_priority = 20 layer1.render_priority = 20
layer2.render_priority = 30 layer2.render_priority = 30
layer0.no_depth_test = true layer0.no_depth_test = true
layer0.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA_DEPTH_PRE_PASS layer0.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA_DEPTH_PRE_PASS
layer0.grow = true layer0.grow = true
@ -47,26 +45,12 @@ func change_all_materials(mesh: MeshInstance3D):
layer2.depth_draw_mode = BaseMaterial3D.DEPTH_DRAW_ALWAYS layer2.depth_draw_mode = BaseMaterial3D.DEPTH_DRAW_ALWAYS
mesh.set_surface_override_material(i, layer0) mesh.set_surface_override_material(i, layer0)
#mesh.set_surface_override_material(i, mat)
#mat.next_pass = preload("control_target_overlay.material")
func unchange_all_materials(mesh: MeshInstance3D): func unchange_all_materials(mesh: MeshInstance3D):
for i in range(mesh.get_surface_override_material_count()): for i in range(mesh.get_surface_override_material_count()):
var mat := mesh.get_active_material(i) var mat := mesh.get_active_material(i)
unchange_material(mat) var layer2: StandardMaterial3D = mat.next_pass.next_pass
while mat.next_pass != null: mesh.set_surface_override_material(i, layer2)
unchange_material(mat.next_pass) layer2.transparency = BaseMaterial3D.TRANSPARENCY_DISABLED
mat = mat.next_pass layer2.depth_draw_mode = BaseMaterial3D.DEPTH_DRAW_OPAQUE_ONLY
mat.next_pass = null
func change_material(mat: BaseMaterial3D) -> BaseMaterial3D:
mat = mat.duplicate()
mat.render_priority = 100
mat.no_depth_test = true
return mat
func unchange_material(mat: BaseMaterial3D) -> BaseMaterial3D:
mat.render_priority = 0
mat.no_depth_test = false
return mat

View File

@ -1,3 +1,4 @@
extends Node extends Node
signal new_target(node: Node) signal new_target(node: Billiard)
signal billiard_touched_billiard(who: Billiard, touched: Billiard)

View File

@ -8,3 +8,9 @@ var can_hit = true
func hit(impulse: Vector3, power: float): func hit(impulse: Vector3, power: float):
apply_central_impulse(impulse * lerp(power_min, power_max, power)) apply_central_impulse(impulse * lerp(power_min, power_max, power))
func _on_body_shape_entered(_body_rid, body, _body_shape_index, _local_shape_index):
if body is Billiard:
ControllerEventBus.billiard_touched_billiard.emit(self, body)

View File

@ -6,9 +6,13 @@
[node name="billiard" type="RigidBody3D"] [node name="billiard" type="RigidBody3D"]
continuous_cd = true continuous_cd = true
max_contacts_reported = 1
contact_monitor = true
script = ExtResource("1_a0fke") script = ExtResource("1_a0fke")
[node name="is_targetable" parent="." instance=ExtResource("2_yrk4o")] [node name="is_targetable" parent="." instance=ExtResource("2_yrk4o")]
[node name="is_TASable" parent="." node_paths=PackedStringArray("_assignedRigidBody3D") instance=ExtResource("3_oj26f")] [node name="is_TASable" parent="." node_paths=PackedStringArray("_assignedRigidBody3D") instance=ExtResource("3_oj26f")]
_assignedRigidBody3D = NodePath("..") _assignedRigidBody3D = NodePath("..")
[connection signal="body_shape_entered" from="." to="." method="_on_body_shape_entered"]