dead parameter

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Kinev

i’ve working in a 2d plataformer in coop with a friend, so i started watching the tutorials made by umai pixel, everything was fine until i reach the part when he code the dead parameters, so in the tutorial he corrected the thing that is happening to me but it’s seen to be changes in the godot program lenguage since then because it didn’t work to me, so when my character is in idle he doesn’t die but when i move or fall in an enemy hitbox then he die and is sent back to the title screen.

here is the part i’m in the tutorial, i watched every coment section but i still don’t find any solution.

:bust_in_silhouette: Reply From: mohamedLT

can you post your code here so we can have better understanding of the problem

okay (meme flecha is a proyectile)
player:
extends KinematicBody2D

const SPEED = 180
const GRAVITY = 20
const JUMP_POWER = -500
const FLOOR = Vector2(0, -1)

const MEMEFLECHA = preload(“res://memeflecha.tscn”)

var velocity = Vector2()

var on_ground = false

var is_attacking = false

var is_dead = false

func _physics_process(delta):

if is_dead == false:

	if Input.is_action_pressed("ui_right"):
		if is_attacking == false:
			velocity.x = SPEED
			$AnimatedSprite.play("run")
			$AnimatedSprite.flip_h = false
			if sign($Position2D.position.x) == -1:
				$Position2D.position.x *=-1
	elif Input.is_action_pressed("ui_left"):
		if is_attacking == false:
			velocity.x = -SPEED
			$AnimatedSprite.play("run")
			$AnimatedSprite.flip_h = true
			if sign($Position2D.position.x) == 1:
				$Position2D.position.x *=-1
	else:
		velocity.x = 0
		if on_ground ==true and is_attacking == false:
			$AnimatedSprite.play("idle")

	if Input.is_action_pressed("ui_up"):
		if is_attacking == false:
			if on_ground == true:
				velocity.y = JUMP_POWER
				on_ground = false

	if Input.is_action_just_pressed("ui_focus_next") and is_attacking == false:
			is_attacking = true
			$AnimatedSprite.play("attack")
			var memeflecha = MEMEFLECHA.instance()
			if sign($Position2D.position.x) == 1:
				memeflecha.set_MemeFlecha_direction(1)
			else:
				memeflecha.set_MemeFlecha_direction(-1)
			get_parent().add_child(memeflecha)
			memeflecha.global_position =  $Position2D.global_position

	velocity.y += GRAVITY

	if is_on_floor():
			if on_ground == false:
				is_attacking = false
			on_ground = true
	else:
		if is_attacking == false:
			on_ground = false
			if velocity.y < 0:
				$AnimatedSprite.play("jump")
			else:
				$AnimatedSprite.play("fall")

	velocity = move_and_slide(velocity, FLOOR)
	
	if get_slide_count() > 0:
		for i in range(get_slide_count()):
			if "Enemy" in get_slide_collision(i).collider.name:
				dead()

func dead():
is_dead = true
velocity = Vector2(0, 0)
$AnimatedSprite.play(“dead”)
$CollisionShape2D.call_deferred(“set_disabled”, true)
$Timer.start()

func _on_AnimatedSprite_animation_finished():
is_attacking = false

func _on_Timer_timeout():
get_tree().change_scene(“StartMenu.tscn”)

enemy:

extends KinematicBody2D

const GRAVITY = 10
export(int) var SPEED = 150
const FLOOR = Vector2(0, -1)

var direction = 1

var is_dead = false

var velocity = Vector2()

func _ready():
pass

func dead():
is_dead = true
velocity = Vector2(0, 0)
$AnimatedSprite.play(“dead”)
$CollisionShape2D.call_deferred(“set_disabled”, true)
$Timer.start()

func _physics_process(delta):
if is_dead == false:
velocity.x = SPEED * direction
if direction == 1:
$AnimatedSprite.flip_h = false
else:
$AnimatedSprite.flip_h = true

	$AnimatedSprite.play("walk")
	
	velocity.y += GRAVITY
	velocity = move_and_slide(velocity, FLOOR)
	

if is_on_wall():
	direction = direction * -1
	$RayCast2D.position.x *= -1
	
if $RayCast2D.is_colliding() == false:
	direction = direction * -1
	$RayCast2D.position.x *= -1
	if get_slide_count() > 0:
		for i in range (get_slide_count()):
			if "Player" in get_slide_collision(i).collider.name:
					get_slide_collision(i).collider.dead()
					$CollisionShape2D.call_deferred("set_disabled", true)

func _on_Timer_timeout():
queue_free()

Kinev | 2020-08-15 00:37

please i need the help

Kinev | 2020-08-15 21:54