My player still moves even after its paused

so once again i messed up my pause menu heres my code i have no idea why hes still moving. edit ive read some of the comments the movement script is the default moving script and ive scatterd it around so i honestly have no clue heres the rest of the pause script @onready var pause_menu = $“player/Camera2D/pause menu”

var paused = false

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _process(_delta):
if Input.is_action_just_pressed(“pause”):
pausemenu()

func pausemenu():
if paused:
pause_menu.hide()
get_tree().paused = false
else:
pause_menu.show()
get_tree().paused = true

paused = !paused

You didn’t give a lot to go off. You could paste in your player’s movement script and the full pause script.

Here’s how: (Not mine, but it works)

Anyways, from the information this post currently provides, have you tried checking if the game is paused when the character movement functions trigger?

Like if is_paused == true: return on the top of the character movement functions.

1 Like

You can check the process_mode of your Node, because in some cases it can still be allowed to process even when paused.

1 Like

In the software developer world there is something called “context” which is really important because without it, it is not possible to understand logics. Next time if you want other people to understand what you are trying to do - so that you can receive help - make sure to add context to your question. This means, sharing the code involved, hopefully in a clear manner.

4 Likes

I still don’t quite understand. what is “hes still moving” ? … try to be more accurate on what you are trying to explain. Okay, but let’s go step by step.

You:

  • are assigning var pause_menu = $“player/Camera2D/pause menu” in some script.

  • also have a variable with initial value of false named paused

  • are using the _process() built in lifecycle method, which contain an Input listener that listens to the action “pause”. Make sure that this action is set up from wherever you are triggering it. To test that it works, use the print() method with some string inside and check in the console if it is actually printing something.

  • in the pausemenu() you are checking the value of the boolean variable to hide or show the node assigned to pause_menu. Then depending on which condition gets triggered you are pausing the entire node tree.

The logic is not that bad. Make sure that the node is correctly assigned to the variable, you can do that by trying to access its properties.

The issue may be related to the action, make sure it is correctly set up.

2 Likes

i mean that the player and enemies still move even when paused sry for my horrible was of explaining crap.

No worries, that is normal when you start in programming. Did you try solving the issue with my suggestions ?

As I mentioned, make sure everything is correctly set-up. I don’t see why it wouldn’t work.

You could also try with another approach. For example: in the _process() method of your moving elements, add a condition which checks if you paused the game and if so, don’t allow it to move.

var some_node: Node  = # a reference to a node goes here

func _porcess():
     if not some_node.has_paused:
             move()
      else: pass

func move():
     # handle the movement logic of this element here

Keep checking and experimenting, that attitude is gold in programming. Every experienced programmer has gone through processes like this. Eventually you will figure it out and make it work.

2 Likes

i greatly appreciate your help this is my first time ever doing programing and ive been relying on tutorials that never explain in detail what stuff means so i appreciate people like you that tells others how and make sense of it.

1 Like

i feel slightly stupid ALL I HAD TO DO WAS SET THEM ALL TO PAUSEABEL :skull::skull::skull::skull::skull::skull::skull::skull::skull::skull::skull::skull::skull:

1 Like

i greatly appreciate your help this is my first time ever doing programing and ive been relying on tutorials that never explain in detail what stuff means so i appreciate people like you that tells others how and make sense of it.

you are welcome, I’m glad to hear that you solved it :clap:

i feel slightly stupid ALL I HAD TO DO WAS SET THEM ALL TO PAUSEABEL :skull::skull::skull::skull::skull::skull::skull::skull::skull::skull::skull::skull::skull:

you are not, I think you are kind of a badass. 13 years old and trying to build a game. which is, by the way, even challenging for experienced programmers.

2 Likes

thx lol