diff --git a/src/Actors/Player.gd b/src/Actors/Player.gd index d93cdf9..958bf64 100644 --- a/src/Actors/Player.gd +++ b/src/Actors/Player.gd @@ -31,7 +31,7 @@ func _physics_process(delta: float) -> void: if _alive: var is_jump_canceled: = Input.is_action_just_released("jump") and !_is_wall_jumping and _velocity.y < 0.0 var direction: = get_direction() - _is_wall_sliding = _velocity.y >=0 and is_on_wall() and !is_on_floor() + _is_wall_sliding = _velocity.y >=0 and _is_next_to_wall() and !is_on_floor() _velocity = calculate_move_velocity(direction,is_jump_canceled, delta) _velocity = move_and_slide(_velocity, Vector2.UP) update_sprite(direction) @@ -48,7 +48,7 @@ func get_direction() -> Vector2: var left_strength = min(Input.get_action_strength("direction_left") * 2, 1) return Vector2( right_strength - left_strength, - -1.0 if Input.is_action_just_pressed("jump") and (is_on_floor() or is_on_wall()) else 1.0 + -1.0 if Input.is_action_just_pressed("jump") and (is_on_floor() or _is_wall_sliding) else 1.0 ) func calculate_move_velocity(direction:Vector2, is_jump_canceled:bool, delta:float)->Vector2: @@ -64,8 +64,9 @@ func calculate_move_velocity(direction:Vector2, is_jump_canceled:bool, delta:fl _in_air = true if _is_wall_sliding: # wall jump + var walljump__x_direction = 1 if _is_next_to_wall_right() else -1 _is_wall_jumping = true - var desired = -(run_speed * wall_jump_speed_factor.x * direction.x) + var desired = -(run_speed * wall_jump_speed_factor.x * walljump__x_direction) output.x = desired output.y = jump_power * wall_jump_speed_factor.y * direction.y pass @@ -109,6 +110,20 @@ func _respawn(): func _revive(): _alive = true + +func _is_next_to_wall(): + return _is_next_to_wall_right() || _is_next_to_wall_left() + +func _is_next_to_wall_right(): + if $RayCastWallRight.is_colliding(): + var colider = $RayCastWallRight.get_collider(); + return colider.name == "SolidsTileMap" + return false +func _is_next_to_wall_left(): + if $RayCastWallLeft.is_colliding(): + var colider = $RayCastWallLeft.get_collider(); + return colider.name == "SolidsTileMap" + return false func update_sprite(direction:Vector2)->void: var air_animation = "jump" if _velocity.y <= 0 else "fall" diff --git a/src/Actors/Player.tscn b/src/Actors/Player.tscn index 6b7d809..9753879 100644 --- a/src/Actors/Player.tscn +++ b/src/Actors/Player.tscn @@ -269,6 +269,9 @@ tracks/1/keys = { [node name="Player" type="KinematicBody2D"] collision_mask = 30 script = ExtResource( 2 ) +__meta__ = { +"_edit_vertical_guides_": [ 5.41509 ] +} [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2( 0, -7 ) @@ -292,7 +295,7 @@ position = Vector2( 0, -8 ) texture = ExtResource( 8 ) vframes = 13 hframes = 8 -frame = 48 +frame = 32 [node name="AnimationPlayer" type="AnimationPlayer" parent="."] autoplay = "idle" @@ -323,4 +326,16 @@ one_shot = true [node name="DashParticlesLeft" parent="." instance=ExtResource( 3 )] [node name="DashParticlesRight" parent="." instance=ExtResource( 1 )] + +[node name="RayCastWallRight" type="RayCast2D" parent="."] +position = Vector2( 0, -8.09363 ) +enabled = true +cast_to = Vector2( 5.2, 0 ) +collision_mask = 8 + +[node name="RayCastWallLeft" type="RayCast2D" parent="."] +position = Vector2( 0, -8.04107 ) +enabled = true +cast_to = Vector2( -5.2, 0 ) +collision_mask = 8 [connection signal="timeout" from="DashTimeout" to="." method="_on_DashTimeout_timeout"]