From 7ca590b90e0cd93d32c75031e0b7ca74b91efe14 Mon Sep 17 00:00:00 2001 From: Jakob Feldmann Date: Mon, 13 Mar 2023 19:03:29 +0100 Subject: [PATCH] Fixed Wallslide Detection --- src/Actors/Blobby/Blobby.gd | 20 +++++++++++++------- src/Actors/Blobby/BlobbyStateMachine.gd | 6 +++++- src/Levels/02 Level.tscn | 10 +++++----- src/Levels/03 Level.tscn | 2 +- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Actors/Blobby/Blobby.gd b/src/Actors/Blobby/Blobby.gd index 5a4fff0..ba9fced 100644 --- a/src/Actors/Blobby/Blobby.gd +++ b/src/Actors/Blobby/Blobby.gd @@ -210,15 +210,21 @@ func is_reversing_horizontal_movement(direction: Vector2) -> bool: # Being able to touch a vertical surface over this length also makes it a qualified "wall" # Also sets wall_touch_direction func is_touching_wall_completely() -> bool: + var value = true for left_raycast in left_wall_raycasts.get_children(): - if left_raycast.is_colliding(): - wall_touch_direction = -1 - return true + wall_touch_direction = -1 + if !left_raycast.is_colliding(): + value = false + continue + if value == true: return value + + value = true for right_raycast in right_wall_raycasts.get_children(): - if right_raycast.is_colliding(): - wall_touch_direction = 1 - return true - return false + wall_touch_direction = 1 + if !right_raycast.is_colliding(): + value = false + continue + return value # Attached to wall state is in the PlayerStateMachine diff --git a/src/Actors/Blobby/BlobbyStateMachine.gd b/src/Actors/Blobby/BlobbyStateMachine.gd index de34b0a..ec470a3 100644 --- a/src/Actors/Blobby/BlobbyStateMachine.gd +++ b/src/Actors/Blobby/BlobbyStateMachine.gd @@ -15,6 +15,7 @@ onready var slope_raycast = get_node("%SlopeRaycast") var facing = 1 var didTurn +var state_time := 0.0 # Adds the intial states func _ready(): @@ -126,7 +127,7 @@ func get_horizontal_direction() -> Vector2: # Determines which state should be active at the moment -func _get_transition(_delta): +func _get_transition(delta): parent.get_node("StateLabel").text = ( self.state # + " x vel:" @@ -135,6 +136,7 @@ func _get_transition(_delta): # + String(round(parent.velocity.y / 10)) ) var new_state + state_time += delta if !parent.is_on_floor(): if parent.velocity.y < 0: new_state = states.jump @@ -175,6 +177,7 @@ func _get_transition(_delta): new_state = states.duck coyote_hanging = false if new_state != self.state: + state_time = 0 return new_state init_boost = false return null @@ -195,6 +198,7 @@ func _enter_state(new_state, old_state): match new_state: states.walk: # TODO I need this when there is a turn happening between two different states + # TODO Queue animation and only play if state time is exceeded, to not play animation on too small jumps/short wallslides if old_state == states.idle && didTurn: anim_state_playback.travel("idleTurn") else: diff --git a/src/Levels/02 Level.tscn b/src/Levels/02 Level.tscn index b396f6f..9f31363 100644 --- a/src/Levels/02 Level.tscn +++ b/src/Levels/02 Level.tscn @@ -87,10 +87,10 @@ wait_time = 20.0 [node name="BlobbyCam" parent="." instance=ExtResource( 12 )] [node name="AnimatedSprite" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="4"] -frame = 6 +frame = 0 [node name="AnimatedSprite2" parent="BlobbyCam/ParallaxBackground/ParallaxLayer5" index="5"] -frame = 11 +frame = 5 [node name="Blobby" parent="." instance=ExtResource( 2 )] unique_name_in_owner = true @@ -109,7 +109,7 @@ position = Vector2( 72, -168 ) script = ExtResource( 5 ) [node name="KinematicBody2D" type="KinematicBody2D" parent="FlyingPlatform"] -collision_layer = 8 +collision_layer = 32 collision_mask = 0 motion/sync_to_physics = true @@ -129,7 +129,7 @@ position = Vector2( 264, -234 ) script = ExtResource( 5 ) [node name="KinematicBody2D" type="KinematicBody2D" parent="FlyingPlatform2"] -collision_layer = 8 +collision_layer = 16 collision_mask = 0 motion/sync_to_physics = true @@ -149,7 +149,7 @@ position = Vector2( 552, -234 ) script = ExtResource( 5 ) [node name="KinematicBody2D" type="KinematicBody2D" parent="FlyingPlatform3"] -collision_layer = 8 +collision_layer = 16 collision_mask = 0 motion/sync_to_physics = true diff --git a/src/Levels/03 Level.tscn b/src/Levels/03 Level.tscn index 7b3c2e5..f91de73 100644 --- a/src/Levels/03 Level.tscn +++ b/src/Levels/03 Level.tscn @@ -139,7 +139,7 @@ shape = SubResource( 3 ) position = Vector2( 0, 1.5 ) z_index = -1 frames = SubResource( 5 ) -frame = 20 +frame = 14 playing = true [node name="Portal" parent="." instance=ExtResource( 42 )]