Skip to content

Commit

Permalink
Add Z forward option to PathFollow3D
Browse files Browse the repository at this point in the history
  • Loading branch information
TokageItLab committed Feb 10, 2023
1 parent f98f92d commit 013bd69
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/classes/PathFollow3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<member name="v_offset" type="float" setter="set_v_offset" getter="get_v_offset" default="0.0">
The node's offset perpendicular to the curve.
</member>
<member name="z_forward" type="bool" setter="set_z_forward" getter="is_z_forward" default="false">
If [code]true[/code], the node moves with the glTF forward axis (+Z) in the front.
</member>
</members>
<constants>
<constant name="ROTATION_NONE" value="0" enum="RotationMode">
Expand Down
15 changes: 15 additions & 0 deletions scene/3d/path_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ void PathFollow3D::_update_transform(bool p_update_xyz_rot) {
t.origin = pos;
} else {
t = c->sample_baked_with_rotation(progress, cubic, false);
if (z_forward) {
t.basis = Basis(t.basis.get_column(1).normalized(), Math_PI) * t.basis;
}
Vector3 forward = t.basis.get_column(2); // Retain tangent for applying tilt
t = PathFollow3D::correct_posture(t, rotation_mode);

Expand Down Expand Up @@ -334,6 +337,9 @@ void PathFollow3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_cubic_interpolation_enabled", "enabled"), &PathFollow3D::set_cubic_interpolation_enabled);
ClassDB::bind_method(D_METHOD("is_cubic_interpolation_enabled"), &PathFollow3D::is_cubic_interpolation_enabled);

ClassDB::bind_method(D_METHOD("set_z_forward", "enabled"), &PathFollow3D::set_z_forward);
ClassDB::bind_method(D_METHOD("is_z_forward"), &PathFollow3D::is_z_forward);

ClassDB::bind_method(D_METHOD("set_loop", "loop"), &PathFollow3D::set_loop);
ClassDB::bind_method(D_METHOD("has_loop"), &PathFollow3D::has_loop);

Expand All @@ -347,6 +353,7 @@ void PathFollow3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "h_offset", PROPERTY_HINT_NONE, "suffix:m"), "set_h_offset", "get_h_offset");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "v_offset", PROPERTY_HINT_NONE, "suffix:m"), "set_v_offset", "get_v_offset");
ADD_PROPERTY(PropertyInfo(Variant::INT, "rotation_mode", PROPERTY_HINT_ENUM, "None,Y,XY,XYZ,Oriented"), "set_rotation_mode", "get_rotation_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "z_forward"), "set_z_forward", "is_z_forward");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cubic_interpolation_enabled"), "set_cubic_interpolation_enabled", "is_cubic_interpolation_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop"), "set_loop", "has_loop");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tilt_enabled"), "set_tilt_enabled", "is_tilt_enabled");
Expand Down Expand Up @@ -429,6 +436,14 @@ PathFollow3D::RotationMode PathFollow3D::get_rotation_mode() const {
return rotation_mode;
}

void PathFollow3D::set_z_forward(bool p_enabled) {
z_forward = p_enabled;
}

bool PathFollow3D::is_z_forward() const {
return z_forward;
}

void PathFollow3D::set_loop(bool p_loop) {
loop = p_loop;
}
Expand Down
5 changes: 5 additions & 0 deletions scene/3d/path_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class PathFollow3D : public Node3D {
ROTATION_ORIENTED
};

bool z_forward = false;

static Transform3D correct_posture(Transform3D p_transform, PathFollow3D::RotationMode p_rotation_mode);

private:
Expand Down Expand Up @@ -118,6 +120,9 @@ class PathFollow3D : public Node3D {
void set_rotation_mode(RotationMode p_rotation_mode);
RotationMode get_rotation_mode() const;

void set_z_forward(bool p_enabled);
bool is_z_forward() const;

void set_cubic_interpolation_enabled(bool p_enabled);
bool is_cubic_interpolation_enabled() const;

Expand Down

0 comments on commit 013bd69

Please sign in to comment.