mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 19:42:43 +00:00
Add error checks for bad configuration in PathFollow2D/3D
set_progress_ratio
When a PathFollow is badly configured it's possible to have code that call get_progress_ratio just after set_progress_ratio does not return the value just set, which may be confusing for developer (ie that myPathFollow2D.set_progress_ratio(0.5) myPathFollow2D.get_progress_ratio() does not return 0.5) This commit makes ensures the developer has useful error messages in such case, to make it easier to troubleshot it.
This commit is contained in:
parent
139f9989e6
commit
ea9dff87ae
@ -26,6 +26,7 @@
|
||||
</member>
|
||||
<member name="progress_ratio" type="float" setter="set_progress_ratio" getter="get_progress_ratio" default="0.0">
|
||||
The distance along the path as a number in the range 0.0 (for the first vertex) to 1.0 (for the last). This is just another way of expressing the progress within the path, as the offset supplied is multiplied internally by the path's length.
|
||||
It can be set or get only if the [PathFollow2D] is the child of a [Path2D] which is part of the scene tree, and that this [Path2D] has a [Curve2D] with a non-zero length. Otherwise, trying to set this field will print an error, and getting this field will return [code]0.0[/code].
|
||||
</member>
|
||||
<member name="rotates" type="bool" setter="set_rotates" getter="is_rotating" default="true">
|
||||
If [code]true[/code], this node rotates to follow the path, with the +X direction facing forward on the path.
|
||||
|
@ -36,6 +36,7 @@
|
||||
</member>
|
||||
<member name="progress_ratio" type="float" setter="set_progress_ratio" getter="get_progress_ratio" default="0.0">
|
||||
The distance from the first vertex, considering 0.0 as the first vertex and 1.0 as the last. This is just another way of expressing the progress within the path, as the progress supplied is multiplied internally by the path's length.
|
||||
It can be set or get only if the [PathFollow3D] is the child of a [Path3D] which is part of the scene tree, and that this [Path3D] has a [Curve3D] with a non-zero length. Otherwise, trying to set this field will print an error, and getting this field will return [code]0.0[/code].
|
||||
</member>
|
||||
<member name="rotation_mode" type="int" setter="set_rotation_mode" getter="get_rotation_mode" enum="PathFollow3D.RotationMode" default="3">
|
||||
Allows or forbids rotation on one or more axes, depending on the [enum RotationMode] constants being used.
|
||||
|
@ -378,10 +378,11 @@ real_t PathFollow2D::get_progress() const {
|
||||
}
|
||||
|
||||
void PathFollow2D::set_progress_ratio(real_t p_ratio) {
|
||||
if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) {
|
||||
ERR_FAIL_NULL_MSG(path, "Can only set progress ratio on a PathFollow2D that is the child of a Path2D which is itself part of the scene tree.");
|
||||
ERR_FAIL_COND_MSG(path->get_curve().is_null(), "Can't set progress ratio on a PathFollow2D that does not have a Curve.");
|
||||
ERR_FAIL_COND_MSG(!path->get_curve()->get_baked_length(), "Can't set progress ratio on a PathFollow2D that has a 0 length curve.");
|
||||
set_progress(p_ratio * path->get_curve()->get_baked_length());
|
||||
}
|
||||
}
|
||||
|
||||
real_t PathFollow2D::get_progress_ratio() const {
|
||||
if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) {
|
||||
|
@ -461,10 +461,11 @@ real_t PathFollow3D::get_progress() const {
|
||||
}
|
||||
|
||||
void PathFollow3D::set_progress_ratio(real_t p_ratio) {
|
||||
if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) {
|
||||
ERR_FAIL_NULL_MSG(path, "Can only set progress ratio on a PathFollow3D that is the child of a Path3D which is itself part of the scene tree.");
|
||||
ERR_FAIL_COND_MSG(path->get_curve().is_null(), "Can't set progress ratio on a PathFollow3D that does not have a Curve.");
|
||||
ERR_FAIL_COND_MSG(!path->get_curve()->get_baked_length(), "Can't set progress ratio on a PathFollow3D that has a 0 length curve.");
|
||||
set_progress(p_ratio * path->get_curve()->get_baked_length());
|
||||
}
|
||||
}
|
||||
|
||||
real_t PathFollow3D::get_progress_ratio() const {
|
||||
if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) {
|
||||
|
Loading…
Reference in New Issue
Block a user