My shader animation is being played on 2 instances.
Asked Answered
T

2

1

So... Basically, I have a AnimationPlayer node in my enemy scene.
I use this shader to make the sprite blink:

shader_type canvas_item;

uniform vec4 flash_color:source_color = vec4(1.0);
uniform float flash_modifier:hint_range(0.0, 1.0, 0.1);

void fragment() {
    vec4 color = texture(TEXTURE, UV);
    color.rgb = mix(color.rgb, flash_color.rgb, flash_modifier);
	COLOR = color;
}

Then, the AnimationPlayer node modifies the shaders parameters in the animation. the animation works fine when there is 1 enemy instance on screen, but if there is more... this happens:

As you can see... When only one enemy takes damage, the other one also plays the shader, but not the whole animation.
This is the animation tracK:

Here is the code when the enemy takes damage:

func take_damage(amount:int) -> void:
	hp -= amount
	animation.play("Hurt")
	velocity.y = -150
	await animation.animation_finished
	if hp <= 0:
		kill()

I have no idea what is going on...

Talkingto answered 10/4, 2023 at 21:15 Comment(0)
L
0

Try to set material resource local to scene.

Launceston answered 10/4, 2023 at 21:34 Comment(0)
T
0

Launceston Holy moly, thanks. I completely forgot about the copied materials lol.

Talkingto answered 10/4, 2023 at 21:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.