| Attention | Topic was automatically imported from the old Question2Answer platform. | |
| Asked By | Nebulabee |
I’m trying to make an object that, when touched, will replenish the player’s ability to double jump. My player character is already able to double jump, and a simple boolean value checks if they have already double jumped to stop them from jumping infinitely (which is reset when they touch the ground).
I want my character’s “has_double_jumped” value to become false whenever it touches this object, so that it can double jump once more. After that, I’ll attach a timer to the object so that the player needs to wait a few seconds before it offers an extra double jump.
How can I make it so the object’s script updates a variable stored in the player? I tried defining a function within the player that replenishes the double jump and calling said function on the object’s script:
func _on_body_entered(body):
if body.name == ‘Player’:
Player.double_jump_returned()
but it returns an error: ‘Identifier ‘Player’ not declared in the current scope’
is there any way to make the player or variables inside it global?
Maybe the below will work
func onbodyentered(body):
if body.name == 'Player':
body.doublejump_returned()
because your checkign if body is the player, but then you try to use a variable named Player to enable double jump again, but in this case body is the player.
You may also be able to do something like
const playerResource = preload("res://path/to/Player.tscn")
func onbodyentered(body):
if body is playerResource:
body.doublejump_returned()
so now you can change the player node’s name without worry
godot_dev_ | 2023-06-17 15:21
Got it to work! Thank you for the help!
Nebulabee | 2023-06-17 16:57