Skip to content

Commit

Permalink
- add custom up vector to the MoveAlongPath script
Browse files Browse the repository at this point in the history
- add show orientation option to the PathScript
- unused script cleanup
  • Loading branch information
Romi Fauzi committed Oct 31, 2021
1 parent 528e04d commit bfc43f5
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 258 deletions.
9 changes: 6 additions & 3 deletions Assets/PathTools/Scenes/PathToolsExample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ MonoBehaviour:
tangentType: 0
selectedId: 0
closeLoop: 1
lastPos: {x: -0.2224189, y: 0.013729572, z: 2.9288592}
lastLeftHandlePos: {x: 2.0906916, y: 0.013729572, z: 3.5246074}
lastRightHandlePos: {x: -2.2515397, y: 0.013729572, z: 2.4062533}
showUpVector: 0
lastPos: {x: 1.4542342, y: 0.013729572, z: 0.3277291}
lastLeftHandlePos: {x: 1.237987, y: 0.013729572, z: -0.6486104}
lastRightHandlePos: {x: 1.6652508, y: 0.013729572, z: 1.2804526}
--- !u!4 &800040797
Transform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -305,6 +306,8 @@ MonoBehaviour:
speed: 2
rotationSpeed: 5
loopMode: 0
useCustomUpVector: 0
customUpVector: {x: 0, y: 1, z: 0}
distance: 0
--- !u!23 &1977854513
MeshRenderer:
Expand Down
51 changes: 0 additions & 51 deletions Assets/PathTools/Scripts/Editor/NodeMoveEditor.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/PathTools/Scripts/Editor/NodeMoveEditor.cs.meta

This file was deleted.

1 change: 1 addition & 0 deletions Assets/PathTools/Scripts/Editor/PathScriptEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public override void OnInspectorGUI()
source.AddNode();

source.closeLoop = EditorGUILayout.Toggle("Close Loop", source.closeLoop);
source.showUpVector = EditorGUILayout.Toggle("Show Orientation", source.showUpVector);
EditorGUILayout.LabelField(string.Format("Path Length: {0}", source.PathDistance));

if (EditorGUI.EndChangeCheck())
Expand Down
6 changes: 5 additions & 1 deletion Assets/PathTools/Scripts/MoveAlongPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public class MoveAlongPath : MonoBehaviour
[SerializeField] float speed = 2f, rotationSpeed = 5f;
[SerializeField] LoopMode loopMode;

[Space(20)]
[SerializeField] bool useCustomUpVector;
[SerializeField] Vector3 customUpVector = Vector3.up;

[Header("Debug")]
[SerializeField] float distance;

Expand Down Expand Up @@ -43,7 +47,7 @@ void Update()
}

transform.position = path.GetPositionAtDistance(runtimeDistance);
Quaternion targetRot = path.GetRotationAtDistance(runtimeDistance, path.GetUpVectorAtDistance(runtimeDistance));
Quaternion targetRot = path.GetRotationAtDistance(runtimeDistance, useCustomUpVector ? customUpVector : path.GetUpVectorAtDistance(runtimeDistance));
transform.rotation = Quaternion.Lerp(transform.rotation, targetRot, rotationSpeed * Time.deltaTime);
}

Expand Down
174 changes: 0 additions & 174 deletions Assets/PathTools/Scripts/NodeMove.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/PathTools/Scripts/NodeMove.cs.meta

This file was deleted.

17 changes: 10 additions & 7 deletions Assets/PathTools/Scripts/PathScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class PathScript : MonoBehaviour
#region VARIABLES
[SerializeField] private List<Node> nodes = new List<Node>();
[SerializeField] private int selectedId;
public bool closeLoop;
public bool closeLoop, showUpVector;

private const int CURVE_SEGMENT = 20;

Expand Down Expand Up @@ -236,13 +236,16 @@ private void OnDrawGizmos()
Gizmos.DrawLine(LocalToWorld(curvedPositions[i == 0 ? curvedPositions.Count - 1 : i - 1]), LocalToWorld(curvedPositions[i]));
}

for (int i = 0; i < orientations.Count; i++)
if (showUpVector)
{
//draw point up with orientation influence
Vector3 direction = (curvedPositions[i] - curvedPositions[i == 0 ? (curvedPositions.Count - 1) : (i - 1)]).normalized;
Vector3 finalDirection = Quaternion.AngleAxis(orientations[i], direction) * Vector3.up;
Gizmos.color = Color.red;
Gizmos.DrawLine(LocalToWorld(curvedPositions[i]), LocalToWorld(curvedPositions[i]) + (finalDirection * 0.4f));
for (int i = 0; i < orientations.Count; i++)
{
//draw point up with orientation influence
Vector3 direction = (curvedPositions[i] - curvedPositions[i == 0 ? (curvedPositions.Count - 1) : (i - 1)]).normalized;
Vector3 finalDirection = Quaternion.AngleAxis(orientations[i], direction) * Vector3.up;
Gizmos.color = Color.red;
Gizmos.DrawLine(LocalToWorld(curvedPositions[i]), LocalToWorld(curvedPositions[i]) + (finalDirection * 0.4f));
}
}
}
#endif
Expand Down

0 comments on commit bfc43f5

Please sign in to comment.