In hit scene:
>animatedsprite
>>timer (it queue free the fx after one sec. I already tried disabling it)
>>area2d
>>>collisionshape2D
Basically the game is turn based, the attack_fx is called during enemy turn if enemy raycast is detecting area2D in front of it.
Right now, the fix seems to copy hit.tscn and put it under a different name. That way it works like before, but for some reason I can’t delete the original hit.tscn or even remove the reference from enemy.gd because it causes the duplicated hit.tscn to also stop working. I feel like maybe something is corrupted.
Edit: Another weird thing happening, if i deleted original hit.tscn and saved the project, it comes back at the project files
Edit2: After further testing, it seems that removing the script from hit.tscn allows it to instanitate normally, so nothing is corrupted?, but i’m not sure what exactly is the problem with it:
extends AnimatedSprite2D
var direction : Vector2 = Vector2.ZERO
func _process(delta: float) -> void:
global_position += direction * 600 * delta
func _on_timer_timeout() -> void:
queue_free() #already tried commenting this out
func _on_area_2d_area_entered(area: Area2D) -> void:
area.owner.animation_player.play("Shake")
area.owner.hit(direction)
Shaker.shake(Globals.camera,4,0.2)
Edit3, commenting that last line in hit script solves it:
func _on_area_2d_area_entered(area: Area2D) -> void:
area.owner.animation_player.play("Shake")
area.owner.hit(direction)
Shaker.shake(Globals.camera,4,0.2) #commenting this line out allows everything to run fine
I’m not sure why this happens though. Here is the autoload shaker
extends Node
func shake(thing , strength: float, duration: float = 0.2) -> void:
if not thing:
return
var orig_pos = thing.position
var shake_count := 10
var tween := create_tween()
for i in shake_count:
var shake_offset := Vector2(randf_range(-1.0, 1.0), randf_range(-1.0, 1.0))
var target = orig_pos + strength * shake_offset
if i % 2 == 0:
target = orig_pos
tween.tween_property(thing, "position", target, duration / float(shake_count))
strength *= 0.75
tween.finished.connect(func(): if thing: thing.position = orig_pos)
Edit4: replacing “Globals.camera” with anything allows it to work normally.
Shaker.shake(Globals.camera,4,0.2)
so now it’s
Shaker.shake(get_tree().get_first_node_in_group("camera"),4,0.2)
Problem solved. I still would like to know why it was not working though, especially that it was working before. Sorry for boring you guys with the edits 