Merge pull request #86474 from KoBeWi/particular_velocity

Only update particle velocity when it changes
This commit is contained in:
Rémi Verschelde 2024-01-08 11:53:53 +01:00
commit 97607b6ab3
No known key found for this signature in database
GPG Key ID: C3336907360768E1
4 changed files with 16 additions and 6 deletions

View File

@ -712,12 +712,15 @@ void GPUParticles2D::_notification(int p_what) {
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
RS::get_singleton()->particles_set_emitter_velocity(particles,
Vector3((get_global_position() - previous_position).x,
(get_global_position() - previous_position).y,
0.0) /
get_process_delta_time());
const Vector3 velocity = Vector3((get_global_position() - previous_position).x, (get_global_position() - previous_position).y, 0.0) /
get_process_delta_time();
if (velocity != previous_velocity) {
RS::get_singleton()->particles_set_emitter_velocity(particles, velocity);
previous_velocity = velocity;
}
previous_position = get_global_position();
if (one_shot) {
time += get_process_delta_time();
if (time > emission_time) {

View File

@ -64,6 +64,7 @@ private:
bool fractional_delta = false;
bool interpolate = true;
float interp_to_end_factor = 0;
Vector3 previous_velocity;
Vector2 previous_position;
#ifdef TOOLS_ENABLED
bool show_visibility_rect = false;

View File

@ -460,7 +460,12 @@ void GPUParticles3D::_notification(int p_what) {
// Use internal process when emitting and one_shot is on so that when
// the shot ends the editor can properly update.
case NOTIFICATION_INTERNAL_PROCESS: {
RS::get_singleton()->particles_set_emitter_velocity(particles, (get_global_position() - previous_position) / get_process_delta_time());
const Vector3 velocity = (get_global_position() - previous_position) / get_process_delta_time();
if (velocity != previous_velocity) {
RS::get_singleton()->particles_set_emitter_velocity(particles, velocity);
previous_velocity = velocity;
}
previous_position = get_global_position();
if (one_shot) {

View File

@ -95,6 +95,7 @@ private:
double emission_time = 0.0;
double active_time = 0.0;
float interp_to_end_factor = 0;
Vector3 previous_velocity;
Vector3 previous_position;
void _attach_sub_emitter();