Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saves try crouch to avoid issues on save game load #307

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions COGITO/CogitoObjects/cogito_player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,11 @@ func _physics_process(delta):


# CROUCH HANDLING dependant on toggle_crouch
if TOGGLE_CROUCH and Input.is_action_just_pressed("crouch"):
try_crouch = !try_crouch
elif !TOGGLE_CROUCH:
try_crouch = Input.is_action_pressed("crouch")
if !is_movement_paused:
if TOGGLE_CROUCH and Input.is_action_just_pressed("crouch"):
try_crouch = !try_crouch
elif !TOGGLE_CROUCH:
try_crouch = Input.is_action_pressed("crouch")


if crouched_jump or (not jumped_from_slide and is_on_floor() and try_crouch or crouch_raycast.is_colliding()):
Expand Down Expand Up @@ -863,6 +864,7 @@ func _physics_process(delta):
is_sprinting = true
if is_crouching:
is_crouching = false
try_crouch = false
elif Input.is_action_pressed("sprint") and !stamina_attribute:
if !Input.is_action_pressed("jump") and CAN_BUNNYHOP:
bunny_hop_speed = SPRINTING_SPEED
Expand All @@ -875,6 +877,7 @@ func _physics_process(delta):
is_sprinting = true
if is_crouching:
is_crouching = false
try_crouch = false
else:
# STANDING UP HANDLING
if !is_showing_ui or !is_movement_paused:
Expand All @@ -886,6 +889,7 @@ func _physics_process(delta):
is_sprinting = false
if is_crouching:
is_crouching = false
try_crouch = false

if Input.is_action_pressed("free_look") or !sliding_timer.is_stopped() and !is_movement_paused:
is_free_looking = true
Expand Down
1 change: 1 addition & 0 deletions COGITO/SceneManagement/cogito_player_state.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var player_state_dir : String = CogitoSceneManager.cogito_state_dir + CogitoScen
@export var player_current_scene_path : String
@export var player_position : Vector3
@export var player_rotation : Vector3
@export var player_try_crouch : bool

#Using Vector2 for saving player attributes. X = current, Y = max.
@export var player_health: Vector2
Expand Down
5 changes: 5 additions & 0 deletions COGITO/SceneManagement/cogito_scene_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func load_player_state(player, passed_slot:String):

player.global_position = _player_state.player_position
player.body.global_rotation = _player_state.player_rotation
player.try_crouch = _player_state.player_try_crouch
# important: ensures the player isn't crouching on game load, regardless
# of whether the option "Toggle Crouching" is set to OFF or ON
player.is_crouching = player.try_crouch

## Loading player sitting state
_player_state.load_sitting_state(player)
Expand Down Expand Up @@ -203,6 +207,7 @@ func save_player_state(player, slot:String):
_player_state.player_current_scene_path = _current_scene_path
_player_state.player_position = player.global_position
_player_state.player_rotation = player.body.global_rotation
_player_state.player_try_crouch = player.try_crouch

## New way of saving attributes:
_player_state.clear_saved_attribute_data()
Expand Down