Fix GPUParticles Inherit Velocity breaking with physics movement
GPUParticles' Inherit Velocity property used to act strangely if the physics tick rate was lower than the rendered FPS, as velocity was tracked in the process and not in the physics process. This means that on certain rendered frames, the velocity was effectively 0 since there was no movement since the last rendered frame.
This commit is contained in:
parent
9425535602
commit
33e1f570ff
2 changed files with 28 additions and 17 deletions
|
|
@ -688,6 +688,7 @@ void GPUParticles2D::_notification(int p_what) {
|
|||
RS::get_singleton()->particles_set_speed_scale(particles, 0);
|
||||
}
|
||||
set_process_internal(true);
|
||||
set_physics_process_internal(true);
|
||||
previous_position = get_global_position();
|
||||
} break;
|
||||
|
||||
|
|
@ -711,15 +712,6 @@ void GPUParticles2D::_notification(int p_what) {
|
|||
} break;
|
||||
|
||||
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||
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) {
|
||||
|
|
@ -739,6 +731,19 @@ void GPUParticles2D::_notification(int p_what) {
|
|||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
||||
// Update velocity in physics process, so that velocity calculations remain correct
|
||||
// if the physics tick rate is lower than the rendered framerate (especially without physics interpolation).
|
||||
const Vector3 velocity = Vector3((get_global_position() - previous_position).x, (get_global_position() - previous_position).y, 0.0) /
|
||||
get_physics_process_delta_time();
|
||||
|
||||
if (velocity != previous_velocity) {
|
||||
RS::get_singleton()->particles_set_emitter_velocity(particles, velocity);
|
||||
previous_velocity = velocity;
|
||||
}
|
||||
previous_position = get_global_position();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue