godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.95k stars 21.15k forks source link

Unknown global transform when Particles2D is set to false for local coordinates and connected to PhysicsBody2D #46933

Open joubertdj opened 3 years ago

joubertdj commented 3 years ago

Godot version: Using Godot 3.22, and also verified with Godot 3.2.4rc4

OS/device including version: Windows 10 Pro OpenGL ES 3.0 Renderer: GeForce RTX 2070 with Max-Q Design/PCIe/SSE2

Issue description: I have a 2d lantern hanging from a chain. The lantern has three particles2d effects on it: Sparks, fire, and smoke. When I set the Local Coords to false for all three particle effects the behavior is expected and when I bump into lantern, the lantern swings and the particles are "left" in global coordinates, as expected.

My intention was to disable emitting of the "fire" particles if the "capture_rect" result is not within the rectangle of the sprite. The result of the "capture_rect" (when the Local Coords is disabled) is in a certain global transform that I cannot "determine"? I have tried the following:

ar _rootGlobalTransform = get_tree().root.get_child(0).get_global_transform() var _tempParticlesRectangle = _rootGlobalTransform.xform(get_node("Lantern_Basic_Particle_Smoke").capture_rect()) print(_tempParticlesRectangle) _tempParticlesRectangle = get_node("Lantern_Basic_Particle_Smoke").capture_rect() print(_tempParticlesRectangle) var _tempParticlesTransform = get_node("Lantern_Basic_Particle_Smoke").get_global_transform() _tempParticlesRectangle = _tempParticlesTransform.xform(get_node("Lantern_Basic_Particle_Smoke").capture_rect()) print(_tempParticlesRectangle)

The first two print instructions provides the same result, hence my assumption is that the coordinates are based upon the global transform, however, the information does not make sense. The third one starts of by saying the rectangle starts at 0,0. If I just enable the Local Coords for the particle system, then (apart from the obvious that the particles move with the lantern), then the result of "capture_rect" makes sense and is as the particles is (if I do the last "print" section as mentioned).

Either the "capture_rect" is computed incorrectly when the Local Coords are set to false or I am missing a specific transform to this?

Minimal reproduction project: I have added a minimal project that demonstrates the behavior: Bug_Capture_Rect.zip

This example has two identical particle system overlapping, one is set to true and the other false for the Local Coords setting, I then display the global and local values recieved.

joubertdj commented 3 years ago

The physics connected to the particle2d seems to maybe cause the issue. The first example I posted actually works ... when I added the chain and Physics things went weird (you can click and drag the ball to interact with the lantern/chain):

Lantern.zip

pouleyKetchoupp commented 3 years ago

I can confirm in 3.2.3 and 3.2.4 RC5: The returned rect seems wrong in the Lantern case where the particles are attached to a chain of rigid bodies. In the project from the original post, it works ok and it seems capture_rect is always in local coordinates, whether local_coords is enabled or not.