Skip to content

Commit

Permalink
feat(Actions): Simple track action now select local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Oct 16, 2024
1 parent dfd4c91 commit 1a0797e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
34 changes: 29 additions & 5 deletions Assets/JCSUnity/Scripts/Actions/JCS_SimpleTrackAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class JCS_SimpleTrackAction : JCS_UnityObject

[Separator("Runtime Variables (JCS_SimpleTrackAction)")]

[Tooltip("Target transform; if null use target position instead.")]
[SerializeField]
private Transform mTarget = null;

[Tooltip("Target position to track.")]
[SerializeField]
private Vector3 mTargetPos = Vector3.zero;
Expand All @@ -45,6 +49,14 @@ public class JCS_SimpleTrackAction : JCS_UnityObject
[SerializeField]
private bool mIgnoreZ = false;

[Tooltip("Use local variables for target instead.")]
[SerializeField]
private bool mLocalTarget = false;

[Tooltip("Use local variables for self instead.")]
[SerializeField]
private bool mLocalSelf = false;

/* Setter & Getter */

public Vector3 TargetPosition { get { return this.mTargetPos; } set { this.mTargetPos = value; } }
Expand All @@ -53,21 +65,33 @@ public class JCS_SimpleTrackAction : JCS_UnityObject
public bool IgnoreX { get { return this.mIgnoreX; } set { this.mIgnoreX = value; } }
public bool IgnoreY { get { return this.mIgnoreY; } set { this.mIgnoreY = value; } }
public bool IgnoreZ { get { return this.mIgnoreZ; } set { this.mIgnoreZ = value; } }
public bool LocalTarget { get { return this.mLocalTarget; } set { this.mLocalTarget = value; } }
public bool LocalSelf { get { return this.mLocalSelf; } set { this.mLocalSelf = value; } }

/* Functions */

private void Update()
{
Vector3 tempTargetPost = mTargetPos;
Vector3 newPos = mTargetPos;

if (mTarget)
{
newPos = (mLocalTarget) ? mTarget.transform.localPosition : mTarget.transform.position;
}

if (mIgnoreX)
tempTargetPost.x = this.LocalPosition.x;
newPos.x = (mLocalSelf) ? LocalPosition.x : Position.x;
if (mIgnoreY)
tempTargetPost.y = this.LocalPosition.y;
newPos.y = (mLocalSelf) ? LocalPosition.y : Position.y;
if (mIgnoreZ)
tempTargetPost.z = this.LocalPosition.z;
newPos.z = (mLocalSelf) ? LocalPosition.z : Position.z;

float time = JCS_Time.DeltaTime(mDeltaTimeType);

this.LocalPosition += (tempTargetPost - LocalPosition) / mFriction * JCS_Time.DeltaTime(mDeltaTimeType);
if (mLocalSelf)
this.LocalPosition += (newPos - LocalPosition) / mFriction * time;
else
this.Position += (newPos - Position) / mFriction * time;
}

/// <summary>
Expand Down
19 changes: 11 additions & 8 deletions docs/ScriptReference/Actions/JCS_SimpleTrackAction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ The action that moves toward a position.

## Variables

| Name | Description |
|:---------------|:-------------------------------------------------|
| mTargetPos | Target position to track. |
| mFriction | How fast it moves toward to the target position? |
| mDeltaTimeType | Type of the delta time. |
| mIgnoreX | Don't track on x-axis? |
| mIgnoreY | Don't track on y-axis? |
| mIgnoreZ | Don't track on z-axis? |
| Name | Description |
|:---------------|:-------------------------------------------------------|
| mTarget | Target transform; if null use target position instead. |
| mTargetPos | Target position to track. |
| mFriction | How fast it moves toward to the target position? |
| mDeltaTimeType | Type of the delta time. |
| mIgnoreX | Don't track on x-axis? |
| mIgnoreY | Don't track on y-axis? |
| mIgnoreZ | Don't track on z-axis? |
| mLocalTarget | Use local variables for target instead. |
| mLocalSelf | Use local variables for self instead. |

## Functions

Expand Down

0 comments on commit 1a0797e

Please sign in to comment.