Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPUParticles2D collisions don't work correctly when using particle animations #91523

Open
reimgrab opened this issue May 3, 2024 · 0 comments

Comments

@reimgrab
Copy link

reimgrab commented May 3, 2024

Tested versions

4.2.stable

System information

Godot v4.2.2.stable.mono - Ubuntu 22.04.4 LTS 22.04 - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1050 Ti (nvidia; 535.171.04) - Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz (4 Threads)

Issue description

GPUParticles2d collisions are using a wrong collision size when particle animations are used.
gpuparticles2d_bug.webm

The expected behaviour in the shown example is that both particles collide the same with the floor.
gpuparticles2d_fixed.webm

Steps to reproduce

-Add a GPUParticles2D to a scene
-Add a sprite sheet texture to it
-Add a CanvasItemMaterial
-Enable particles animation on the material and set its v_ and h_frames

Minimal reproduction project (MRP)

gpuparticles2d_bug.zip

The above shown expected behaviour can be achieved with this patch (against 4.3 master):

diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp
index bc39513c03..6dc33567b1 100644
--- a/scene/2d/gpu_particles_2d.cpp
+++ b/scene/2d/gpu_particles_2d.cpp
@@ -216,7 +216,14 @@ void GPUParticles2D::_update_collision_size() {
 	real_t csize = collision_base_size;
 
 	if (texture.is_valid()) {
-		csize *= (texture->get_width() + texture->get_height()) / 4.0; //half size since its a radius
+		int twidth = texture->get_width();
+		int theight = texture->get_height();
+		CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr());
+		if (mat && mat->get_particles_animation()) {
+			twidth /= mat->get_particles_anim_h_frames();
+			theight /= mat->get_particles_anim_v_frames();
+		}
+		csize *= (twidth + theight) / 4.0; //half size since its a radius
 	}
 
 	RS::get_singleton()->particles_set_collision_base_size(particles, csize);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants