Skip to content

Commit

Permalink
Implement LookAtModifier3D
Browse files Browse the repository at this point in the history
  • Loading branch information
TokageItLab committed Oct 23, 2024
1 parent 80f0b33 commit 84d3d88
Show file tree
Hide file tree
Showing 5 changed files with 896 additions and 0 deletions.
126 changes: 126 additions & 0 deletions doc/classes/LookAtModifier3D.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="LookAtModifier3D" inherits="SkeletonModifier3D" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
</brief_description>
<description>
This [SkeletonModifier3D] rotates a bone to look a target. This is extremely helpful for moving character's head to look at the player, rotating a turret to look at a target, or any other case where you want to make a bone rotate towards something quickly and easily.
</description>
<tutorials>
</tutorials>
<methods>
<method name="get_interpolation_remain" qualifiers="const">
<return type="float" />
<description>
Returns the remaining seconds of the time-based interpolation.
</description>
</method>
<method name="is_interpolating" qualifiers="const">
<return type="bool" />
<description>
Returns whether the time-based interpolation is running or not. If [code]true[/code], it is equivalent to [method get_interpolation_remain] being [code]0[/code].
This is useful to determine whether a [LookAtModifier3D] can be removed safely.
</description>
</method>
<method name="is_target_within_limitation" qualifiers="const">
<return type="bool" />
<description>
Returns whether the target is within the angle limitations. It is useful for unsetting the [member target_node] when the target is outside of the angle limitations.
[b]Note:[/b] The value is updated after [method SkeletonModifier3D._process_modification]. To retrieve this value correctly, we recommend using the signal [signal SkeletonModifier3D.modification_processed].
</description>
</method>
</methods>
<members>
<member name="bone" type="int" setter="set_bone" getter="get_bone" default="0">
The bone index of the [Skeleton3D] that the modification will operate on.
</member>
<member name="duration" type="float" setter="set_duration" getter="get_duration" default="0.0">
The duration of the time-based interpolation. Interpolation is triggered at the following cases:
- When the target node is changed
- When an axis is flipped due to angle limitation
[b]Note:[/b] The flipping occurs when the target is outside the angle limitation and the internally computed secondary rotation axis of the forward vector is flipped. Visually, it occurs when the target is outside the angle limitation and crosses the plane of the [member forward_axis] and [member primary_rotation_axis].
</member>
<member name="ease_type" type="int" setter="set_ease_type" getter="get_ease_type" enum="Tween.EaseType" default="0">
The ease type of the time-based interpolation. See also [enum Tween.EaseType].
</member>
<member name="forward_axis" type="int" setter="set_forward_axis" getter="get_forward_axis" enum="LookAtModifier3D.BoneAxis" default="4">
The forward axis of the bone. This [SkeletonModifier3D] modifies the bone so that this axis points toward the [member target_node].
</member>
<member name="primary_damp_threshold" type="float" setter="set_primary_damp_threshold" getter="get_primary_damp_threshold">
The threshold to start damping for [member primary_limit_angle]. It provides non-linear(logarithmic) interpolation, let it feel more resistance the more it rotate to the edge limit. This is useful for simulating the limits of human motion.
If [code]1.0[/code], no damping is performed. If [code]0.0[/code], damping is performed always.
</member>
<member name="primary_limit_angle" type="float" setter="set_primary_limit_angle" getter="get_primary_limit_angle">
The limit angle of the primary rotation when [member symmetry_limitation] is [code]true[/code].
</member>
<member name="primary_negative_damp_threshold" type="float" setter="set_primary_negative_damp_threshold" getter="get_primary_negative_damp_threshold">
The threshold to start damping for [member primary_negative_limit_angle].
</member>
<member name="primary_negative_limit_angle" type="float" setter="set_primary_negative_limit_angle" getter="get_primary_negative_limit_angle">
The limit angle of negative side of the primary rotation when [member symmetry_limitation] is [code]false[/code].
</member>
<member name="primary_positive_damp_threshold" type="float" setter="set_primary_positive_damp_threshold" getter="get_primary_positive_damp_threshold">
The threshold to start damping for [member primary_positive_limit_angle].
</member>
<member name="primary_positive_limit_angle" type="float" setter="set_primary_positive_limit_angle" getter="get_primary_positive_limit_angle">
The limit angle of positive side of the primary rotation when [member symmetry_limitation] is [code]false[/code].
</member>
<member name="primary_rotation_axis" type="int" setter="set_primary_rotation_axis" getter="get_primary_rotation_axis" enum="Vector3.Axis" default="1">
The axis of the first rotation. This [SkeletonModifier3D] works by compositing the rotation by Euler angles to prevent to rotate the [member forward_axis].
</member>
<member name="secondary_damp_threshold" type="float" setter="set_secondary_damp_threshold" getter="get_secondary_damp_threshold">
The threshold to start damping for [member secondary_limit_angle].
</member>
<member name="secondary_limit_angle" type="float" setter="set_secondary_limit_angle" getter="get_secondary_limit_angle">
The limit angle of the secondary rotation when [member symmetry_limitation] is [code]true[/code].
</member>
<member name="secondary_negative_damp_threshold" type="float" setter="set_secondary_negative_damp_threshold" getter="get_secondary_negative_damp_threshold">
The threshold to start damping for [member secondary_negative_limit_angle].
</member>
<member name="secondary_negative_limit_angle" type="float" setter="set_secondary_negative_limit_angle" getter="get_secondary_negative_limit_angle">
The limit angle of negative side of the secondary rotation when [member symmetry_limitation] is [code]false[/code].
</member>
<member name="secondary_positive_damp_threshold" type="float" setter="set_secondary_positive_damp_threshold" getter="get_secondary_positive_damp_threshold">
The threshold to start damping for [member secondary_positive_limit_angle].
</member>
<member name="secondary_positive_limit_angle" type="float" setter="set_secondary_positive_limit_angle" getter="get_secondary_positive_limit_angle">
The limit angle of positive side of the secondary rotation when [member symmetry_limitation] is [code]false[/code].
</member>
<member name="symmetry_limitation" type="bool" setter="set_symmetry_limitation" getter="is_limitation_symmetry">
If [code]true[/code], the limitations are spread from the bone symmetrically.
If [code]false[/code], the limitation can be specified separately for each side of the bone rest.
</member>
<member name="target_node" type="NodePath" setter="set_target_node" getter="get_target_node" default="NodePath(&quot;&quot;)">
The [NodePath] to the node that is the target for the look at modification. This node is what the modification will rotate the bone to.
</member>
<member name="transition_type" type="int" setter="set_transition_type" getter="get_transition_type" enum="Tween.TransitionType" default="0">
The transition type of the time-based interpolation. See also [enum Tween.TransitionType].
</member>
<member name="use_angle_limitation" type="bool" setter="set_use_angle_limitation" getter="is_using_angle_limitation" default="false">
If [code]true[/code], limits the degree of rotation. This helps prevent the character's neck from rotating 360 degrees.
[b]Note:[/b] As with [AnimationTree] blending, interpolation is provided that favors [method Skeleton3D.get_bone_rest]. This means that interpolation does not select the shortest path in some cases.
</member>
<member name="use_secondary_rotation" type="bool" setter="set_use_secondary_rotation" getter="is_using_secondary_rotation" default="true">
If [code]true[/code], provides rotation by two axes.
</member>
</members>
<constants>
<constant name="BONE_AXIS_PLUS_X" value="0" enum="BoneAxis">
Enumerated value for the +X axis.
</constant>
<constant name="BONE_AXIS_MINUS_X" value="1" enum="BoneAxis">
Enumerated value for the -X axis.
</constant>
<constant name="BONE_AXIS_PLUS_Y" value="2" enum="BoneAxis">
Enumerated value for the +Y axis.
</constant>
<constant name="BONE_AXIS_MINUS_Y" value="3" enum="BoneAxis">
Enumerated value for the -Y axis.
</constant>
<constant name="BONE_AXIS_PLUS_Z" value="4" enum="BoneAxis">
Enumerated value for the +Z axis.
</constant>
<constant name="BONE_AXIS_MINUS_Z" value="5" enum="BoneAxis">
Enumerated value for the -Z axis.
</constant>
</constants>
</class>
1 change: 1 addition & 0 deletions editor/icons/LookAtModifier3D.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 84d3d88

Please sign in to comment.