fix: hang physics more predictable

This commit is contained in:
Sara Gerretsen 2026-05-06 13:55:39 +02:00
parent 7baa148c53
commit 25d6411f87
3 changed files with 16 additions and 12 deletions

Binary file not shown.

View file

@ -173,6 +173,7 @@ script/source = "@tool extends RayCast3D
@onready var body : PlayerBody = get_owner() as Node3D
@export var dist_mul : float
@export var height : float = 1.0
var last_direction : Vector3 = Vector3.BACK
func _ready() -> void:
@ -180,7 +181,7 @@ func _ready() -> void:
func _physics_process(_delta : float):
if Engine.is_editor_hint() and body:
global_position = body.global_position + Vector3.UP + Vector3.BACK * dist_mul
global_position = body.global_position + Vector3.UP * height + Vector3.BACK * dist_mul
elif body:
var direction : Vector3 = -body.velocity
if body.is_on_wall():
@ -188,7 +189,7 @@ func _physics_process(_delta : float):
direction = Vector3(direction.x, 0, direction.z).normalized()
if not direction.is_zero_approx():
last_direction = direction
global_position = body.global_position + Vector3.UP + last_direction * dist_mul
global_position = body.global_position + Vector3.UP * height + last_direction * dist_mul
"
[sub_resource type="GDScript" id="GDScript_3rerk"]
@ -201,7 +202,7 @@ func _ready():
%LedgeHangTimer.timeout.connect(set.bind(\"timeout\", false))
func _enter() -> int:
if not timeout and not body.is_on_floor() and blackboard.hang_ray.is_colliding() and blackboard.hang_ray.get_collision_normal().y > 0.9 and body.is_on_wall():
if not timeout and blackboard.hang_ray.is_colliding() and blackboard.hang_ray.get_collision_normal().y > 0.9 and body.is_on_wall():
timeout = true
return Success
else:
@ -217,16 +218,19 @@ var wall_normal : Vector3
func _enter() -> int:
blackboard.anim.set(\"parameters/Ledge/request\", AnimationNodeOneShot.ONE_SHOT_REQUEST_FIRE)
wall_normal = body.get_wall_normal()
blackboard.character.look_at(blackboard.character.global_position - Vector3(wall_normal.x, 0, wall_normal.z))
wall_normal = Vector3(wall_normal.x, 0, wall_normal.z).normalized()
blackboard.character.look_at(blackboard.character.global_position - wall_normal)
return Running
func _execute() -> int:
var diff : Vector3 = blackboard.hang_ray.get_collision_point() - blackboard.hang_ray.global_position
body.velocity = Vector3(body.velocity.x * 0.7, diff.y * 15., body.velocity.z * 0.7)
var input_dot_wall : float = wall_normal.dot(blackboard.get_world_move_input())
if diff.length() < 0.05 and input_dot_wall < -0.5:
return Success
return Running
if get_status() == Running:
var diff : Vector3 = blackboard.hang_ray.get_collision_point() - blackboard.hang_ray.global_position
body.velocity = Vector3.ZERO
body.global_position = body.global_position.lerp(body.global_position + diff, 0.25)
var input_dot_wall : float = wall_normal.dot(blackboard.get_world_move_input())
if diff.length() < 0.05 and input_dot_wall < -0.5:
return Success
return get_status()
func _exit():
%LedgeHangTimer.start()