From 7d5fd39cd82fde7e7a13ed5e4d55a2ccfe29a958 Mon Sep 17 00:00:00 2001 From: Nathan Lovato Date: Thu, 9 May 2019 10:12:45 +0900 Subject: [PATCH] Move hook reaction code to Character.gd --- prototypes/1.hook-movement/Character.gd | 10 ++++++++-- prototypes/1.hook-movement/Hook.gd | 15 ++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/prototypes/1.hook-movement/Character.gd b/prototypes/1.hook-movement/Character.gd index 21b51ef..b3d60b7 100644 --- a/prototypes/1.hook-movement/Character.gd +++ b/prototypes/1.hook-movement/Character.gd @@ -104,5 +104,11 @@ func _set_info_dict(value:Dictionary) -> void: Events.emit_signal("player_info_updated", _info_dict) -func _on_Hook_hooked_onto_target(force:Vector2) -> void: - _velocity += force +# Hook reaction temporarily moved to the player to make it easier to customize the reaction +# in different prototypes +func _on_Hook_hooked_onto_target(target_position:Vector2) -> void: + var PULL_BASE_FORCE: = 2500.0 + var to_target: = target_position - global_position + var direction: = to_target.normalized() + var distance: = to_target.length() + _velocity += direction * PULL_BASE_FORCE * pow(distance / hook.length, 0.3) diff --git a/prototypes/1.hook-movement/Hook.gd b/prototypes/1.hook-movement/Hook.gd index bdf1f8d..6ca2b52 100644 --- a/prototypes/1.hook-movement/Hook.gd +++ b/prototypes/1.hook-movement/Hook.gd @@ -5,9 +5,8 @@ throws a raycast that can interact with Hookable bodies and calculate a pull vec The raycast is updated manually for greater precision with where the player is aiming """ -signal hooked_onto_target(pull_force) +signal hooked_onto_target(target_position) -export var PULL_BASE_FORCE: = 2500.0 onready var ray: RayCast2D = $RayCast2D onready var arrow: = $Arrow @@ -25,7 +24,7 @@ func _unhandled_input(event: InputEvent) -> void: if event.is_action_pressed("hook") and _can_hook(): cooldown.start() arrow.hook_position = snap_detector.target.global_position if snap_detector.target else ray.get_collision_point() - emit_signal("hooked_onto_target", _calculate_pull_force()) + emit_signal("hooked_onto_target", _get_hook_position()) func _physics_process(delta: float) -> void: @@ -52,14 +51,8 @@ func _has_target() -> bool: func _can_hook() -> bool: return _has_target() and cooldown.is_stopped() - -func _calculate_pull_force() -> Vector2: - var target_position: Vector2 = snap_detector.target.global_position if snap_detector.target else ray.get_collision_point() - var to_target: = target_position - global_position - var direction: = to_target.normalized() - var distance: = to_target.length() - return PULL_BASE_FORCE * pow(distance / length, 0.6) * direction - +func _get_hook_position() -> Vector2: + return snap_detector.target.global_position if snap_detector.target else ray.get_collision_point() func _get_aim_direction() -> Vector2: match Settings.controls: