Browse Source

Merge pull request #53003 from KoBeWi/tween_0()

Rémi Verschelde 3 years ago
parent
commit
5e4a71200e
2 changed files with 5 additions and 0 deletions
  1. 1 0
      doc/classes/Tween.xml
  2. 4 0
      thirdparty/misc/easing_equations.cpp

+ 1 - 0
doc/classes/Tween.xml

@@ -86,6 +86,7 @@
 				[code]initial_value[/code] is the starting value of the interpolation.
 				[code]initial_value[/code] is the starting value of the interpolation.
 				[code]delta_value[/code] is the change of the value in the interpolation, i.e. it's equal to [code]final_value - initial_value[/code].
 				[code]delta_value[/code] is the change of the value in the interpolation, i.e. it's equal to [code]final_value - initial_value[/code].
 				[code]duration[/code] is the total time of the interpolation.
 				[code]duration[/code] is the total time of the interpolation.
+				[b]Note:[/b] If [code]duration[/code] is equal to [code]0[/code], the method will always return the final value, regardless of [code]elapsed_time[/code] provided.
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="is_running">
 		<method name="is_running">

+ 4 - 0
thirdparty/misc/easing_equations.cpp

@@ -312,6 +312,10 @@ Tween::interpolater Tween::interpolaters[Tween::TRANS_MAX][Tween::EASE_MAX] = {
 };
 };
 
 
 real_t Tween::run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d) {
 real_t Tween::run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d) {
+	if (d == 0) {
+		// Special case to avoid dividing by 0 in equations.
+		return b + c;
+	}
 
 
 	interpolater cb = interpolaters[p_trans_type][p_ease_type];
 	interpolater cb = interpolaters[p_trans_type][p_ease_type];
 	ERR_FAIL_COND_V(cb == NULL, b);
 	ERR_FAIL_COND_V(cb == NULL, b);