mirror of
https://github.com/GDQuest/godot-platformer-2d.git
synced 2026-07-25 11:53:49 +00:00
Move hook reaction code to Character.gd
This commit is contained in:
parent
2fb6c2f4af
commit
7d5fd39cd8
2 changed files with 12 additions and 13 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue