Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Frenggie |
Hey. I am trying to implement a jump potion into my game which changes the jump height of player from -600 to -1000. I have declared the jump height variable in a script called “globals.gd” which is an enabled singleton.
For some reason the new jump height (of -1000) ist only applied when my KinematicBody2D (the Player) has died and the current scene is reloaded but not when he collects the jump potion (Area2D with signal “body_entered”).
please show the scripts.
whiteshampoo | 2020-05-27 13:27
Sry, my bad. I cut it to the relevant parts.
The Player.gd
var JUMP_HEIGHT = Globals.JUMP_HEIGHT # globals singleton
func _physics_process(delta):
#The jump part
if is_on_floor():
if Input.is_action_just_pressed("ui_up"):
motion.y = JUMP_HEIGHT
if friction == true:
motion.x = lerp(motion.x, 0, 0.1)
The jump_potion.gd
func _on_Jump_Potion_body_entered(body):
set_process(true)
if body.name == "Player":
Globals.JUMP_HEIGHT = -1000
$Timer.start()
print("AREA ENTERED")
queue_free()
else:
pass
func _on_Timer_timeout():
Globals.JUMP_HEIGHT = -600
The globals.gd (singleton)
var JUMP_HEIGHT = -600
Frenggie | 2020-05-27 13:40