P
pink_mantis

  • Sep 13, 2024
  • Joined Jul 18, 2022
  • 0 best answers
  • Fixed ! All control nodes should be placed in a canvas layer node. A good lesson !

  • Hey everyone !
    I have 2 parallax nodes in my game tree, one showing in the front of my player, enemies, objects, and a huge collection of background parallax. My foreground is showing in front of everything, and that's great, but i still want my control nodes working on the cutscenes to show in front, yet the foreground always pops through !

    I've been tinkering with the Z axis for a few day, but the only way I found to hide the foreground from the cutscenes nodes is to change the z axis to -1 (or lower), and even tho my player has a z axis of -50 it still show up in front of it !
    I should mention my player is instanced in the ready func of the tree but i'm not sure how it would affect it at all.
    Here I've shown my tree and my foreground showing on top of the transition_scene node, even though that one is at a 100 on the z axis.

    Thank you so much and have a good one !

    pink

  • Solved ! For anyone wondereing, a division using int numbers usually rounds up to an int. I just had to change alpha = (title_count - 100) / 100 to alpha = (title_count - 100) / 100.0. Works wonders !

    pink

  • I'm sorry I can't manage to post it without the code looking like shite...

    Btw i'm calling start from another node and the $ProgressBar works just fine !

  • Hi everyone !

    I'm trying to update an alpha variable on the modulate of my Label. Unforunately it absolutely doesn't work ! the letters just popo out of existance and actually never go back to hiding. The code is really simple so i'm baffled !

    Here it is :

    extends Control

    var start = false
    var title_count = 0
    var alpha = 0

    func _ready():
    await get_tree().create_timer(0.2).timeout
    $Label.text = get_parent().get_parent().level_text

    func _process(delta):
    if start == true :
    $ProgressBar.value = title_count * 2
    if title_count >= 100 and title_count < 200 :
    alpha = (title_count - 100) / 100
    $Label.set_modulate(Color(1,1,1,alpha))
    if title_count > 300 :
    alpha = (title_count - 300) / 100
    $Label.set_modulate(Color(1,1,1, 100 - alpha))
    $ProgressBar.value = 100 - ((title_count - 300) * 2)
    $ProgressBar.fill_mode = 1
    if title_count > 600 : start = false
    title_count += 1

    Thanks for taking a look !

    pink

  • Thanks to both of you i managed to do it (which means i probably have a few too many lines of code).
    You saved my evening thank you ! And many more evenings to come !

    Have a great one people. Thanks !

  • Hi everyone !

    I'm trying to change a global variable (of an upgrade) through another node.
    I have an upgrade menu in which there are many of them and each have and export variable written as upgrade = "speed_upgrade", or upgrade = "bomb_upgrade". I'd love to have my Global script get that name, find the variable with the same name and update it.
    What i'd love is to find a way to transfer the upgrade var from my UI (to know which is selected) to my Global (easy, just have another upgrade var in Global) and then find that variable by name in my Global and update, like this :

    Global.upgrade = upgrade
    Global.get(upgrade) += 1

    Unfortunately, only the first line works (because obviously the second line finds what's stored in the variable and tries to update it... nowhere ?

    I hope it's not to confusing. Thanks so much for the time.

    Have a good one !

    pink

  • Hi everyone ! I've been having some trouble working on a space shooter. I'd love to have a parallax background moving on its own on the x axis but I can't seem to make it move on its own !
    After looking it up, it seems the very simplest option is the very best, and I've typed a ParallaxBackground script. Here it is :

    extends ParallaxBackground

    @export var scrolling_speed = 10

    func _process(delta):
    scroll_base_offset.x -= scrolling_speed

    Unfortunately, nothing moves. A few youtube tutorials seem to have it working really well ? I've also tried with the scroll_offset but
    I might just have missed a little box to check or something. Thank you so much for the read and for your help !

    pink

    • extends RigidBody2D
      
      var Name = "Animal"
      var working_planet = "none"
      var working_planet_position = Vector2(0,0)
      var velocity = Vector2()
      
      var color1 = 0
      var color2 = 0
      var color3 = 0
      var type = 0
      var action = 0
      var action_time = 0
      var action_speed = 1
      
      func _ready() -> void :
      	var rng = RandomNumberGenerator.new()
      	rng.randomize()
      	color1 = rng.randf_range(0, 1)
      	rng.randomize()
      	color2 = rng.randf_range(0, 1)
      	rng.randomize()
      	color3 = rng.randf_range(0, 1)
      	$AnimatedSprite.modulate = Color(color1, color2, color3, 1)
      	
      	rng.randomize()
      	action_speed = rng.randf_range(1,2)
      
      
      func _process(delta: float) -> void:
      	
      	
      	look_at(working_planet_position)
      	rotation_degrees += 270
      	var rotating = get_rotation_degrees()
      	
      	
      	var rng = RandomNumberGenerator.new()
      	action_time += action_speed
      	if action_time >= 100 :
      		rng.randomize()
      		action = rng.randi_range(0,2)
      		action_time = 0
      	if action == 0 :
      		velocity = Vector2(1, 0).rotated(rotation)
      		if $AnimatedSprite.frame > type * 5 + 3 :
      			$AnimatedSprite.frame = type * 5
      		$AnimatedSprite.flip_h = true
      	elif action == 1 :
      		velocity = Vector2(-1, 0).rotated(rotation)
      		if $AnimatedSprite.frame > type * 5 + 3 :
      			$AnimatedSprite.frame = type * 5
      		$AnimatedSprite.flip_h = false
      	elif action == 2 :
      		velocity = Vector2(0,0)
      		$AnimatedSprite.frame = type * 5 + 4
      	position += velocity
      
      	pass
    • extends RigidBody2D
      
      var Name = "Planet"
      const WASTE = preload("res://SCENES/Waste.tscn")
      const ANIMAL = preload("res://SCENES/Animal.tscn")
      var PLANT = preload("res://SCENES/Plant.tscn")
      var type = 0
      var size = 0
      var x : int = 0
      var pos = Vector2()
      var animal_type = 0
      var minimap_icon = "planet"
      
      
      func _ready() -> void:
      	###PLANET
      	var rng = RandomNumberGenerator.new()
      	$Sprite.frame = type
      	rng.randomize()
      	size = rng.randi_range(0, 3)
      	if size == 0 :
      		scale = Vector2(0.5,0.5)
      	if size == 2 :
      		scale = Vector2(2,2)
      	if size == 3 :
      		scale = Vector2(3,3)
      	
      	rng.randomize()
      	if size < 2 :
      		type = rng.randi_range(0, 2)
      	elif size > 1 :
      		type = rng.randi_range(2, 4)
      	
      	pos.x = rng.randi_range(-15000, 15000)
      	pos.y = rng.randi_range(-15000, 15000)
      	position = pos
      	
      	###ANIMALS
      	rng.randomize()
      	animal_type = rng.randi_range(0, 2)
      
      func _process(delta: float) -> void:
      	###WASTE
      	if type == 0 :
      		while x < 1 :
      			var waste = WASTE.instance()
      			var new_waste = waste
      			add_child(new_waste)
      			
      			var plant = PLANT.instance()
      			var new_plant = plant
      			add_child(new_plant)
      			
      			var animal = ANIMAL.instance()
      			var new_animal = animal
      			animal.working_planet_position = position
      			animal.type = animal_type
      			add_child(animal)
      			x += 1
      	if type == 1 :
      		while x < 2 :
      			var waste = WASTE.instance()
      			var new_waste = waste
      			add_child(new_waste)
      			
      			var plant = PLANT.instance()
      			var new_plant = plant
      			add_child(new_plant)
      			
      			var animal = ANIMAL.instance()
      			var new_animal = animal
      			animal.working_planet_position = position
      			animal.type = animal_type
      			add_child(animal)
      			x += 1
      	if type == 2 :
      		while x < 3 :
      			var waste = WASTE.instance()
      			var new_waste = waste
      			add_child(new_waste)
      			
      			var plant = PLANT.instance()
      			var new_plant = plant
      			add_child(new_plant)
      			
      			var animal = ANIMAL.instance()
      			var new_animal = animal
      			animal.working_planet_position = position
      			animal.type = animal_type
      			add_child(animal)
      			x += 1
      			x += 1
      	if type == 3 :
      		while x < 5 :
      			var waste = WASTE.instance()
      			var new_waste = waste
      			add_child(new_waste)
      			
      			var plant = PLANT.instance()
      			var new_plant = plant
      			add_child(new_plant)
      			
      			var animal = ANIMAL.instance()
      			var new_animal = animal
      			animal.working_planet_position = position
      			animal.type = animal_type
      			add_child(animal)
      			x += 1
      			
      	if type == 4 :
      		while x < 7 :
      			var waste = WASTE.instance()
      			var new_waste = waste
      			add_child(new_waste)
      			
      			var plant = PLANT.instance()
      			var new_plant = plant
      			add_child(new_plant)
      			
      			var animal = ANIMAL.instance()
      			var new_animal = animal
      			animal.working_planet_position = position
      			animal.type = animal_type
      			add_child(animal)
      			x += 1
      		
      		
      
      func _on_Area2D_body_entered(body: Node) -> void:
      	if (body.Name == "Planet" and body.name != name) :
      		queue_free()
    • Thank you so much ! Unfortunately i'm creating the animal instances from the planets. Everything's a child of the Level1 node, some created by script others children of the node before starting the program (like the player which i did make local, unfortunately didn't help). Here the codes first of the planets, then of the animals. Sorry, everything is very poorly coded, i'm still learning and hard coding everything !
      Thanks again !

    • Hey everyone !
      Working on a little arcade 2D game where you go from planet to planet (each one being a new center of gravity), i realized that all of the actions my player has creating Particles2D are sometimes pushing away animals (not other rigidbody2Ds) from the center of the planet. I cannot find a link anywhere between those two possibly interracting with each other. Another thing to note is once animals from one planet move away from the center, all other animals move away from theirs ! I cannot for the life of me understand how this is happening. I don't want to flood my own post but I'd post anycode requested.

      Thank you so much for reading ! Here's a few pics depicting the problem :

    • Thank you so much to both of you ! I realize i've just layed a huge chunk of code unto everyone, I hope it doesn't seem rude. Disabling the CollisionShape2D of my player seems to do the trick (even though i just fall through my tile map). I've tried cutting out chunk of code but I can't find anything else making a difference.

      Thank you so much for the editing of the post ! I'm very grateful for both of your looking out.

      pink

    • Hello ! New to the forum (as an asker) but I'd really love some help ! Touching both of my enemies (based on a similar code) on a special spot (center top or center bottom) makes them disappear ! They do not go through the "dying" phase and they just disappear from the game (a line making a += 1 on my batteries while alive confirms it). The problem is I don't see a queue_free susceptible to erase them anywhere ! I'll share my code with you lovely people still and wish upon a star some gentle and smart soul comes and save me from this 2 weeks nightmare.
      Thank you so much !

      Enemy 1

      extends KinematicBody2D
      
      
      const PLAYER = preload("res://SCENES/Player/Player.tscn")
      const BULLET = preload("res://SCENES/Objects/Bullet.tscn")
      const FALLDUST = preload("res://SCENES/Objects/FallDust.tscn")
      var hp = 30
      var speed = 150
      var velocity = Vector2()
      export var direction = -1
      var idle = true
      var attack0 = false
      var attack1 = false
      var attack2 = false
      var attack_counter = 0
      var damage = 25
      var character_instance = preload("res://SCENES/Characters/Shrooms/Ellen.tscn")
      var character = character_instance.instance()
      
      
      func _ready():
      	if direction == 1:
      		$AnimatedSprite.flip_h = true
      
      ##Movement ??
      func _physics_process(delta):
      	if hp > 0:
      		if is_on_wall():
      			direction *= -1
      			$AnimatedSprite.flip_h = not $AnimatedSprite.flip_h
      		
      		velocity.y += Global.gravity
      		
      		if hp > 0:
      			if idle :
      				$AnimatedSprite.play("idle")
      				velocity.x = (speed * direction) - (hp/4 * direction)
      				attack_counter += 1
      				if attack_counter > 200 + hp/4:
      					idle = false
      					attack0 = true
      					attack_counter = 0
      			elif attack0 :
      				$AnimatedSprite.play("attack0")
      				velocity.x = 0
      				attack_counter += 1
      				if attack_counter > 20 + hp/4:
      					attack_counter = 0
      					attack0 = false
      					attack1 = true
      			elif attack1 :
      				$AnimatedSprite.play("jump")
      				if is_on_floor():
      					velocity.y = -500
      					attack1 = false
      					attack2 = true
      			elif attack2 :
      				if !is_on_floor():
      					velocity.x = (speed * 1.5 * direction)
      				else :
      					$AnimatedSprite.play("land")
      					velocity.x = 0
      					if attack_counter < 1:
      						get_parent().get_parent().add_child(FALLDUST.instance())
      					attack_counter += 1
      					if attack_counter > 60:
      						attack2 = false
      						idle = true
      			
      	velocity = move_and_slide(velocity, Vector2.UP)
      		
      	#DEATH
      	if hp <= 0:
      		if $AnimatedSprite.scale.x <= 1.5 :
      			$Explosion.visible = true
      			$Explosion.playing = true
      			$CollisionShape2D.scale.y += 0.002
      			$AnimatedSprite.play("shocked")
      			$Particles2D.one_shot = true
      			$AnimatedSprite.scale.x += 0.001
      			$AnimatedSprite.scale.y += 0.001
      		if $AnimatedSprite.scale.x >= 1.5 :
      			$AnimatedSprite.play("death")
      		velocity = Vector2(0,0)
      		set_collision_layer_bit(4, false)
      		set_collision_mask_bit(0, false)
      		$sides_checker.set_collision_layer_bit(4, false)
      		$sides_checker.set_collision_mask_bit(0, false)
      		$Battery.parent_dead = true
      
      
      
      ## HURT
      func ouch(var enemyposx, var bouncexforce):
      	$HurtTimer.start()
      	set_modulate(Color(1,0.3,0.3,0.7))
      	$AnimatedSprite.play("shocked")
      
      
      func _on_HurtTimer_timeout():
      	set_modulate(Color(1,1,1,1))
      
      
      ## COLLISION PLAYER
      func _on_sides_checker_body_entered(body):
      	var layer = body.get_collision_layer()
      	if layer == 1:
      		Global.batteries -= damage
      		body.ouch(position.x, 500)
      		
      
      ##DIE AND CREATE
      func _on_AnimatedSprite_animation_finished():
      	if $AnimatedSprite.scale.x >= 1.5:
      		var pos = global_position
      		character.global_position = pos
      		$"../../PNJ".add_child(character)
      		queue_free()

      Enemy 2

      extends KinematicBody2D
      
      
      const PLAYER = preload("res://SCENES/Player/Player.tscn")
      const BULLET = preload("res://SCENES/Objects/Bullet.tscn")
      #const BADBULLET = preload("")
      var hp = 50
      var speed = 150
      var velocity = Vector2()
      export var direction = -1
      var attack = 0
      var attack_counter = 0
      var next_attack = false
      var damage = 25
      
      ##Movement ??
      func _physics_process(delta):
      	Global.batteries += 1
      	if hp > 0:
      		attack_counter += 1
      		if attack == 0 :
      			if attack_counter < 150:
      				$AnimatedSprite.play("idle")
      			elif attack_counter > 150 + hp:
      				$AnimatedSprite.play("land")
      				next_attack = true
      		elif attack == 1 : #OUT AND SHOOT
      			$AnimatedSprite.play("out")
      			if attack_counter == 50 or attack_counter == 100 or attack_counter == 150 :
      				pass
      			if attack_counter > 200 + hp:
      				attack += 1
      				pass
      		elif attack == 2 :
      			$AnimatedSprite.play("jump")
      			next_attack = true
      		elif attack >= 3:
      			attack = 0
      			next_attack = false
      			attack_counter = 0
      	#DEATH
      	if hp <= 0:
      		$AnimatedSprite.play("death")
      		speed = 0
      		velocity = Vector2(0,0)
      		set_collision_layer_bit(4, false)
      		set_collision_mask_bit(0, false)
      		$sides_checker.set_collision_layer_bit(4, false)
      		$sides_checker.set_collision_mask_bit(0, false)
      		$Battery.parent_dead = true
      
      
      
      
      
      func _on_sides_checker_body_entered(body):
      	var layer = body.get_collision_layer()
      	if layer == 1:
      		Global.batteries -= damage
      		body.ouch(position.x, 500)
      
      
      func _on_AnimatedSprite_animation_finished():
      	if next_attack == true:
      		attack += 1
      		attack_counter = 0
      		next_attack = false

      Player

      extends KinematicBody2D
      
      ##POWERS
      export var dark = false
      export var hug = false
      export var lovegun = true
      export var lovesword = true
      
      
      ###CARACS
      export var speed = 12
      var velocity = Vector2(0,0)
      export var gravity = 15
      export var slide_speed = 25
      export var jump_force = -380
      export var wall_jumpx = 250
      export var wall_jumpy = -330
      export var bounce_force = 0.7
      export var batteries = 0
      export var stop_speed = 12
      export var max_speed = 200
      export var starting_speed = 40
      var bullet_cost = Global.bullet_cost
      var sword_cost = Global.sword_cost
      
      
      
      
      ##ANIMATIONS
      var swordattacking = false
      ##GLOBAL
      const BULLET = preload("res://SCENES/Objects/Bullet.tscn")
      const SWORD = preload("res://SCENES/Objects/LoveSword.tscn")
      #CAMERA
      var collision_shape = 0
      var size = 0
      var cam = 0
      
      
      
      
      func _ready():
      	position = Vector2(Global.wheretox, Global.wheretoy)
      
      
      ## POWERS START
      	if dark == false:
      		$Light2D.enabled = false
      	if lovegun == false:
      		$SpriteGun.visible = false
      	if lovesword == false:
      		$SpriteSword.visible = false
      
      
      #CAMERA MOVEMEMENT
      
      
      func _on_RoomDetector_area_entered(area: Area2D) -> void:
      	collision_shape = area.get_node("CollisionShape2D")
      	size = collision_shape.shape.extents*2
      	cam = $Camera2D
      
      
      func _physics_process(delta):
      	
      	##MORE CAMERA MOVEMENT
      	if sign($Position2D.position.x) == -1 :
      		if cam.global_position.x > collision_shape.global_position.x - size.x/2 - cam.offset.x :
      			if cam.offset.x >= -74 :
      				cam.offset.x -= cam.smoothing_speed * (1-(cam.offset.x/-74))
      			else : pass
      	else :
      		if cam.global_position.x < collision_shape.global_position.x + size.x/2 + cam.offset.x :
      			if cam.offset.x <= 74:
      				cam.offset.x += cam.smoothing_speed * (1-(cam.offset.x/74))
      	
      	
      	cam.limit_top = collision_shape.global_position.y - size.y/2
      	cam.limit_left = collision_shape.global_position.x - size.x/2 - cam.offset.x
      	cam.limit_bottom = collision_shape.global_position.y + size.y/2
      	cam.limit_right = collision_shape.global_position.x + size.x/2 - cam.offset.x
      	
      	
      	if Global.talking == false:
      		#MOVING
      		if Input.is_action_pressed("ui_right"):
      			velocity.x += speed
      			$Sprite.flip_h = false
      			$SpriteGun.flip_h = false
      			$SpriteSword.flip_h = false
      			if not next_to_wall():
      				if sign($Position2D.position.x) == -1:
      					$Position2D.position.x *= -1;
      		if Input.is_action_pressed("ui_left"):
      			velocity.x -= speed
      			$Sprite.flip_h = true
      			$SpriteGun.flip_h = true
      			$SpriteSword.flip_h = true
      			if not next_to_wall():
      				if sign($Position2D.position.x) == 1:
      					$Position2D.position.x *= -1;
      		if !Input.is_action_pressed("ui_left") and !Input.is_action_pressed("ui_right") or Input.is_action_pressed("ui_left") and Input.is_action_pressed("ui_right"):
      			if velocity.x > stop_speed and velocity.x != 0:
      				velocity.x -= stop_speed;
      			elif velocity.x < -stop_speed:
      				velocity.x += stop_speed
      			else:
      				velocity.x = 0;
      		if Input.is_action_just_pressed("ui_select"):
      			if is_on_floor():
      				velocity.y = jump_force
      			if next_to_right_wall():
      				velocity.y += wall_jumpy
      				velocity.x -= wall_jumpx
      			if next_to_left_wall():
      				velocity.y += wall_jumpy
      				velocity.x += wall_jumpx
      		
      		if not next_to_wall():
      			velocity.y += gravity
      		elif next_to_wall() and velocity.x == 0 :
      			velocity.y = slide_speed;
      		
      		velocity = move_and_slide(velocity, Vector2.UP)
      		
      		if velocity.x > max_speed:
      			velocity.x -= speed;
      		if velocity.x < -max_speed:
      			velocity.x += speed;
      			
      
      		#SHOOTING
      		if Input.is_action_just_pressed("ui_changeweapon"):
      			Global.weapon_selected += 1
      			if Global.weapon_selected > Global.weapons_available:
      				Global.weapon_selected = 1
      		if lovegun == true and Global.weapon_selected == 2:
      			if Input.is_action_just_pressed("ui_shoot"):
      				if Global.batteries > 0:
      					Global.batteries -= bullet_cost
      					var bullet = BULLET.instance()
      					get_parent().add_child(bullet)
      					if Input.is_action_pressed("ui_up") and !next_to_wall():
      						bullet.set_bullet_directiony(-1)
      						bullet.position = global_position
      					elif Input.is_action_pressed("ui_down")and !next_to_wall() and !is_on_floor():
      						bullet.set_bullet_directiony(1)
      						bullet.position = global_position
      					elif Input.is_action_pressed("ui_down")and !next_to_wall():
      						bullet.set_bullet_directionx(1)
      						bullet.position = $Position2D.global_position
      					elif sign($Position2D.position.x) == 1:
      						bullet.set_bullet_directionx(1)
      						bullet.position = $Position2D.global_position
      					else:
      						bullet.set_bullet_directionx(-1)
      						bullet.position = $Position2D.global_position
      				else: pass
      		elif lovesword == true and Global.weapon_selected == 1 and swordattacking == false:
      			if Input.is_action_just_pressed("ui_shoot"):
      				if Global.batteries > 0:
      					swordattacking = true
      					Global.batteries -= sword_cost
      					var sword = SWORD.instance()
      					get_parent().add_child(sword)
      					if Input.is_action_pressed("ui_up") and !next_to_wall():
      						sword.set_bullet_directiony(-1)
      						sword.position.x = global_position.x
      						sword.position.y = global_position.y - 16
      					elif Input.is_action_pressed("ui_down")and !next_to_wall() and !is_on_floor():
      						sword.set_bullet_directiony(1)
      						sword.position = global_position
      					elif Input.is_action_pressed("ui_down")and !next_to_wall():
      						sword.set_bullet_directionx(1)
      						sword.position = $Position2D.global_position
      					elif sign($Position2D.position.x) == 1:
      						sword.set_bullet_directionx(1)
      						sword.position = $Position2D.global_position
      					else:
      						sword.set_bullet_directionx(-1)
      						sword.position = $Position2D.global_position
      		elif lovesword == true : velocity.x /= 2
      	
      	if batteries > 999:
      		batteries = 999
      
      
      # ANIMATION
      
      	##WEAPONS
      	if Global.weapon_selected == 1:
      		$SpriteSword.visible = true
      	else :
      		$SpriteSword.visible = false
      	if Global.weapon_selected == 2:
      		$SpriteGun.visible = true
      	else :
      		$SpriteGun.visible = false
      	
      	
      	if next_to_wall():
      		$Sprite.play("WallSlide")
      		$SpriteGun.play("WallSlide")
      		$SpriteSword.play("WallSlide")
      		if next_to_left_wall():
      			$Sprite.flip_h = false
      			$SpriteGun.flip_h = false
      			if sign($Position2D.position.x) == -1:
      				$Position2D.position.x *= -1;
      		if next_to_right_wall():
      			$Sprite.flip_h = true
      			$SpriteGun.flip_h = true
      			if sign($Position2D.position.x) == 1:
      				$Position2D.position.x *= -1;
      	elif swordattacking == true:
      		$Sprite.play("SwordAttack")
      		$SpriteSword.play("SwordAttack")
      	elif not is_on_floor() and Input.is_action_pressed("ui_up"):
      		$Sprite.play("JumpUp")
      		$SpriteGun.play("JumpUp")
      		$SpriteSword.play("JumpUp")
      	elif not is_on_floor() and Input.is_action_pressed("ui_down"):
      		$Sprite.play("JumpDown")
      		$SpriteGun.play("JumpDown")
      		$SpriteSword.play("JumpDown")
      	elif not is_on_floor():
      		$Sprite.play("Jump")
      		$SpriteGun.play("Jump")
      		$SpriteSword.play("Jump")
      	elif velocity.x < -stop_speed and Input.is_action_pressed("ui_up") or velocity.x > stop_speed and Input.is_action_pressed("ui_up"):
      		$Sprite.play("RunningUp")
      		$SpriteGun.play("RunningUp")
      		$SpriteSword.play("RunningUp")
      	elif velocity.x < -stop_speed or velocity.x > stop_speed:
      		$Sprite.play("Running")
      		$SpriteGun.play("Running")
      		$SpriteSword.play("Running")
      	elif  Input.is_action_pressed("ui_up"):
      		$Sprite.play("LookUp")
      		$SpriteGun.play("LookUp")
      		$SpriteSword.play("LookUp")
      	elif  Input.is_action_pressed("ui_down"):
      		$Sprite.play("LookDown")
      		$SpriteGun.play("LookDown")
      		$SpriteSword.play("LookDown")
      	else:
      		$Sprite.play("Idle")
      		$SpriteGun.play("Idle")
      		$SpriteSword.play("Idle")
      
      
      ##   WALLJUMP
      func next_to_wall():
      	if hug == true:
      		if not is_on_floor():
      			return next_to_right_wall() or next_to_left_wall()
      
      func next_to_right_wall():
      	if not is_on_floor() and velocity.y >= 0:
      		return $RightWall.is_colliding()
      		if sign($Position2D.position.x) == 1:
      			$Position2D.position.x *= -1;
      func next_to_left_wall():
      	if not is_on_floor() and velocity.y >= 0:
      		return $LeftWall.is_colliding()
      		if sign($Position2D.position.x) == -1:
      			$Position2D.position.x *= -1;
      
      
      
      
      func _on_deathzone_body_entered(body):
      	get_tree().change_scene("res://Level1.tscn")
      
      func bounce():
      	velocity.y = jump_force * bounce_force
      func ouch(var enemyposx, var bouncexforce):
      	$HurtTimer.start()
      	set_modulate(Color(1,0.3,0.3,0.7))
      	velocity.y = jump_force * bounce_force
      	if position.x < enemyposx:
      		velocity.x = -bouncexforce
      	elif position.x > enemyposx:
      		velocity.x = bouncexforce
      	Input.action_release("ui_left")
      	Input.action_release("ui_right")
      
      
      
      func _on_HurtTimer_timeout():
      	set_modulate(Color(1,1,1,1))
      
      
      
      
      func _on_Sprite_animation_finished() -> void:
      	if swordattacking == true : 
      		swordattacking = false