Checkpoint in rope mechanics

Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
This commit is contained in:
Ethan Wellenreiter 2025-01-03 14:12:01 -05:00
parent 0c726db9ea
commit ac6e3e7a0a
2 changed files with 10 additions and 7 deletions

View File

@ -57,7 +57,7 @@ func _physics_process(delta: float) -> void:
#tangential_direction = Vector2(conn_dir.y, -conn_dir.x) # counter-clockwise tangential
#tangential_direction = tangential_direction.normalized()
velocity = velocity.project(tangential_direction)
velocity = velocity.project(tangential_direction) # takes the part of the velocity that is tangent the the swing arc
#print(tangential_direction)
#print(velocity)
#print(pow(DAMPENING, delta))
@ -69,13 +69,18 @@ func _physics_process(delta: float) -> void:
#print("swaying")
velocity += delta*SWING_SWAY*(tangential_direction* (1 if direction > 0 else -1)).normalized()
move_and_slide()
if position.distance_to(connection_points[-1]) != rope_length:
var diff :float = rope_length - position.distance_to(connection_points[-1]) # negative if farther
#print(diff)
#print(conn_dir.normalized())
position -= conn_dir.normalized()*diff
#print(position.distance_to(connection_points[-1]), " ", rope_length)
pass
else:
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
@ -88,7 +93,5 @@ func _physics_process(delta: float) -> void:
velocity.x = clamp(velocity.x + (direction*delta*acting_speed), -WALK_SPEED, WALK_SPEED)
else:
velocity.x = move_toward(velocity.x, 0, SLOW_SPEED_MULTIPLIER*WALK_SPEED*delta)
move_and_slide()
move_and_slide()
#print("v3: ", velocity)

View File

@ -1,4 +1,4 @@
extends RayCast2D
extends Node2D
class_name Rope
@onready var player : Player = get_parent()