0 votes

At the moment I am working on the environment of a level and I tried including things like grass. That grass was supposed to go away(after the animation passes) when a collision box enters it's area. The Player has a collision box and an attack that activates a Hurt box(collision box). The problem is that the collision box is not registered by the grass or the player is ignored. A way that I know the code in the grass works is that if I stack the grass on top of each other they destroy each other and the animation happens. This happens due to the grass having it's own collision and detecting each other. The player just passes through and is not detected.

This is the code I used in the Grass:

extends Node2D

func creategrasseffect():
var GrassEffect = load("res://Effects/GrassEffect.tscn")
var grassEffect = GrassEffect.instance()
var world = gettree().currentscene
world.addchild(grassEffect)
grassEffect.global
position = global_position

func onHurtBoxareaentered(area):
create
grasseffect()
queue
free()

And this is the code for the Grass Animation:

extends Node2D

onready var animatedSprite = $AnimatedSprite

func _ready():
animatedSprite.frame = 0
animatedSprite.play("Animate")

func onAnimatedSpriteanimationfinished():
queue_free()

The animation is "Animate"

My player code is( If you are wondering) this:

extends KinematicBody2D

const ACCELERATION = 1000
const MAX_SPEED = 5000
const FRICTION = 1000

enum {
MOVE,
ROLL,
ATTACK
}

var state = MOVE
var velocity = Vector2.ZERO

onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")

func _ready():
animationTree.active = true

func process(delta):
match state :
MOVE:
move
state(delta)

    ROLL:
        pass

    ATTACK:
        attack_state(delta)

func movestate(delta):
var input
vector = Vector2.ZERO
inputvector.x = Input.getactionstrength("uiright") - Input.getactionstrength("uileft")
input
vector.y = Input.getactionstrength("uidown") - Input.getactionstrength("uiup")
inputvector = inputvector.normalized()

if input_vector != Vector2.ZERO:
    animationTree.set("parameters/Idle/blend_position", input_vector)
    animationTree.set("parameters/Run/blend_position", input_vector)
    animationTree.set("parameters/Attack/blend_position", input_vector)
    animationState.travel("Run")
    velocity += input_vector * ACCELERATION * delta
    velocity = velocity.clamped(MAX_SPEED * delta)
else:
    animationState.travel("Idle")
    velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

velocity = move_and_slide(velocity)

if Input.is_action_just_pressed("attack"):
    state = ATTACK

func attack_state(delta):
velocity = Vector2.ZERO
animationState.travel("Attack")

func attackstatefinish():
state = MOVE

If you have questions I will answer at the best of my abilities.

Godot version Godot Engine V3.2.3.stable.official
in Engine by (17 points)

1 Answer

0 votes
func onHurtBoxareaentered(area):
if area.name == "nameothePlayerHurtbox"
    creategrasseffect()
    queue_free()

do you checked your layers/mask collisions?

by (18 points)
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.