From 76e7f5ef1977d8caad320c1a6045c14201216d48 Mon Sep 17 00:00:00 2001 From: Dustin Date: Tue, 3 Jun 2025 14:37:44 -0700 Subject: [PATCH] Spent too much time fixing slope movement --- Main.tscn | 2 +- .../LegacyFantasy-High_Forest/tileset.tres | 8 +++--- lib/classes/movement_state_receiver.gd | 28 +++++++++++++++---- .../playerE/PlayerE-Movement_StateReceiver.gd | 14 ++++++++-- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Main.tscn b/Main.tscn index baee89c..bfd08ca 100644 --- a/Main.tscn +++ b/Main.tscn @@ -2,7 +2,7 @@ [ext_resource path="res://src/classes/camera_guide.gd" type="Script" id=1] [ext_resource path="res://src/Camera2D.gd" type="Script" id=2] -[ext_resource path="res://src/levels/CloneBox.tscn" type="PackedScene" id=3] +[ext_resource path="res://src/levels/TestBox.tscn" type="PackedScene" id=3] [ext_resource path="res://src/ui/scene_transition.tscn" type="PackedScene" id=4] [ext_resource path="res://src/ui/HUD.tscn" type="PackedScene" id=5] [ext_resource path="res://src/Main.gd" type="Script" id=7] diff --git a/assets/levels/LegacyFantasy-High_Forest/tileset.tres b/assets/levels/LegacyFantasy-High_Forest/tileset.tres index ff46254..f00d2ea 100644 --- a/assets/levels/LegacyFantasy-High_Forest/tileset.tres +++ b/assets/levels/LegacyFantasy-High_Forest/tileset.tres @@ -18,16 +18,16 @@ points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) [sub_resource type="ConvexPolygonShape2D" id=6] -points = PoolVector2Array( 0, 15.8622, 0, 12.2812, 0, 8.62056, 16, 0, 16, 16 ) +points = PoolVector2Array( 0, 16, 0, 8, 0, 8, 16, 0, 16, 16 ) [sub_resource type="ConvexPolygonShape2D" id=7] -points = PoolVector2Array( 16, 8.69844, 16, 16, 0, 16 ) +points = PoolVector2Array( 16, 8, 16, 16, 0, 16 ) [sub_resource type="ConvexPolygonShape2D" id=8] -points = PoolVector2Array( 0, 0, 16, 8.46479, 16, 16, 0, 16 ) +points = PoolVector2Array( 0, 0, 16, 8, 16, 16, 0, 16 ) [sub_resource type="ConvexPolygonShape2D" id=9] -points = PoolVector2Array( 0, 8.62056, 16, 16, 0, 16 ) +points = PoolVector2Array( 0, 8, 16, 16, 0, 16 ) [sub_resource type="ConvexPolygonShape2D" id=10] points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) diff --git a/lib/classes/movement_state_receiver.gd b/lib/classes/movement_state_receiver.gd index e5d0188..780d21d 100644 --- a/lib/classes/movement_state_receiver.gd +++ b/lib/classes/movement_state_receiver.gd @@ -40,6 +40,8 @@ const UP = -1.0 const DOWN = 1.0 const LEFT = -1.0 const RIGHT = 1.0 +#const TILE_SIZE = 4 +var FLOOR_ANGLE_THRESHOLD := deg2rad(60) func _ready(): #velocity_controller.debug = true @@ -164,10 +166,24 @@ func apply_state_modifier(movement_parameters :MovementParameters) -> MovementPa ## Passed in acceleration, vel, etc is applied to whatever ## the parent is. If Kinematic then move_and_slide, otherwise manually adjusted func apply_movement_to_parent( _velocity :Vector2) -> void: - var snap = Vector2.DOWN * 8 - ## Disable snap when trying to jump (hacky?) - if _velocity.y < -8: - snap = Vector2.ZERO - if parent is KinematicBody2D: - velocity_controller.velocity = parent.move_and_slide_with_snap(_velocity, snap , Vector2.UP, true) + #var snap = Vector2((_velocity.normalized().x * -1 * TILE_SIZE) ,DOWN * TILE_SIZE) + var snap = Vector2.DOWN #* TILE_SIZE + + #var snap = Vector2.DOWN + ## Disable snap when trying to jump (hacky?) + if !current_state.is_grounded: + snap = Vector2.ZERO + + if parent is KinematicBody2D: + #velocity_controller.velocity = parent.move_and_slide_with_snap(_velocity, snap , Vector2.UP, true, 4, FLOOR_ANGLE_THRESHOLD) + #velocity_controller.velocity.x = parent.move_and_slide(_velocity,Vector2.UP,false,TILE_SIZE,FLOOR_ANGLE_THRESHOLD).x + velocity_controller.velocity = parent.move_and_slide_with_snap(_velocity, snap , Vector2.UP, true, 4, FLOOR_ANGLE_THRESHOLD) + if !parent.is_on_floor() and parent.get_slide_count() == 0: + var collision_to_floor = parent.get_floor_angle() + var collision_count = parent.get_slide_count() + var foo = 2+2 + + + #move_and_slide_with_snap(linear_velocity: Vector2, snap: Vector2, up_direction: Vector2 = Vector2( 0, 0 ), stop_on_slope: bool = false, max_slides: int = 4, floor_max_angle: float = 0.785398, infinite_inertia: bool = true) + diff --git a/src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd b/src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd index dd45414..cec19d8 100644 --- a/src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd +++ b/src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd @@ -397,9 +397,6 @@ func _state_process_physics_move(): request_state_change.call_func('idle') return - if !parent.is_on_floor(): - request_state_change.call_func('fall') - return ## First version #move_actor_as_desired() @@ -416,6 +413,17 @@ func _state_process_physics_move(): desired_movement_vector ) ) + ## Doing this after the call of movement + if !parent.is_on_floor(): + request_state_change.call_func('fall') + return + +# var slide_count = parent.get_slide_count() +# ## TODO: Our impulse model can't handle zero +# if velocity_controller.velocity.y > - 2 and parent.get_slide_count() == 0: +# request_state_change.call_func('fall') +# return + func get_climb_shape_location() -> Vector2: if $"%LadderDetector".is_colliding(): var point: Vector2 = $"%LadderDetector".get_collision_point()