0 votes

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.
https://www.youtube.com/watch?v=1_dqnDxP6lQ&list=PLyckz_-Rzq6ClGevL2fneJ5YJnMPKWa4M&index=14

in Engine by (12 points)

1 Answer

0 votes

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

by (102 points)

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 physicsprocess(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():
isdead = true
velocity = Vector2(0, 0)
$AnimatedSprite.play("dead")
$CollisionShape2D.call
deferred("set_disabled", true)
$Timer.start()

func onAnimatedSpriteanimationfinished():
is_attacking = false

func onTimertimeout():
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():
isdead = true
velocity = Vector2(0, 0)
$AnimatedSprite.play("dead")
$CollisionShape2D.call
deferred("set_disabled", true)
$Timer.start()

func physicsprocess(delta):
if isdead == 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 onTimertimeout():
queue
free()

please i need the help

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.