Skip to content

Commit 1a4dbe0

Browse files
committed
Added new "Look At" options to BezierWalkers for 2D games: "X Forward" and "Y Forward". Note that previous "Forward" option is now renamed to "Z Forward" for consistency
1 parent 000d9ca commit 1a4dbe0

File tree

6 files changed

+16
-41
lines changed

6 files changed

+16
-41
lines changed

Plugins/BezierSolution/README.txt

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,4 @@
1-
= Bezier Solution (v2.3.3) =
1+
= Bezier Solution (v2.3.4) =
22

3-
Online documentation & example code available at: https://github.com/yasirkula/UnityBezierSolution
4-
E-mail: yasirkula@gmail.com
5-
6-
### ABOUT
7-
This plugin helps you create bezier splines either visually in editor or by code during gameplay. Includes some utility functions like finding the closest point on the spline or travelling the spline with constant speed. It is built upon Catlike Coding's spline tutorial: https://catlikecoding.com/unity/tutorials/curves-and-splines/
8-
9-
10-
### HOW TO
11-
To create a new spline in the editor, click "GameObject - Bezier Spline". Now you can select the end points of the spline in the Scene view and move/rotate/scale or delete/duplicate them as you wish (each end point also has 2 control points that can be moved around). Most variables have explanatory tooltips.
12-
13-
You can tweak the Scene view gizmos via "Project Settings/yasirkula/Bezier Solution" page (on older versions, this menu is located at "Preferences" window).
14-
15-
The plugin comes with some additional components that may help you move objects or particles along splines. These components are located in the Utilities folder:
16-
17-
- BezierWalkerWithSpeed: Moves an object along a spline with constant speed. There are 3 travel modes: Once, Ping Pong and Loop. If Look At is Forward, the object will always face forwards. If it is SplineExtraData, the extra data stored in the spline's end points is used to determine the rotation. You can modify this extra data from the points' Inspector. The smoothness of the rotation can be adjusted via Rotation Lerp Modifier. Normalized T determines the starting point. Each time the object completes a lap, its On Path Completed () event is invoked. To see this component in action without entering Play mode, click the "Simulate In Editor" button.
18-
19-
- BezierWalkerWithTime: Travels a spline in Travel Time seconds. Movement Lerp Modifier parameter defines the smoothness applied to the position of the object. If High Quality is enabled, the spline will be traversed with constant speed but the calculations can be more expensive.
20-
21-
- BezierWalkerLocomotion: Allows you to move a number of objects together with this object on a spline. This component must be attached to an object with a BezierWalker component (tail objects don't need a BezierWalker, though). Look At, Movement Lerp Modifier and Rotation Lerp Modifier parameters affect the tail objects. If tail objects jitter too much, enabling High Quality may help greatly but the calculations can be more expensive.
22-
23-
- ParticlesFollowBezier: Moves particles of a Particle System in the direction of a spline. It is recommended to set the Simulation Space of the Particle System to Local for increased performance. This component affects particles in one of two ways:
24-
-- Strict: particles will strictly follow the spline. They will always be aligned to the spline and will reach the end of the spline at the end of their lifetime. This mode performs slightly better than Relaxed mode
25-
-- Relaxed: properties of the particle system like speed, Noise and Shape will affect the movement of the particles. Particles in this mode will usually look more interesting. If you want the particles to stick with the spline, though, set their speed to 0
26-
27-
- BezierAttachment: Snaps an object to the specified point of the spline. You can snap the object's position and/or rotation values, optionally with some offsets. Rotation can be snapped in one of two ways:
28-
-- Use Spline Normals: spline's normal vectors will be used to determine the object's rotation
29-
-- Use End Point Rotations: the Transform rotation values of the spline's end points will be used to determine the object's rotation
30-
31-
- BezierLineRenderer: Automatically positions a Line Renderer's points so that its shape matches the target spline's shape. It is possible to match the shape of only a portion of the spline by tweaking the Spline Sample Range property. If Line Renderer's "Use World Space" property is enabled, then its points will be placed at the spline's current position. Otherwise, the points will be placed relative to the Line Renderer's position and they will rotate/scale with the Line Renderer.
32-
33-
- BendMeshAlongBezier: Modifies a MeshFilter's mesh to bend it in the direction of a spline (make sure that the spline's normals are perpendicular to the spline; Auto Calculate Normals may help). If High Quality is enabled, evenly spaced bezier points will be used so that the mesh bends uniformly but the calculations will be more expensive. If Auto Refresh is enabled, the mesh will be refreshed automatically when the spline is modified (at runtime, this has the same effect with disabling the component but in edit mode, disabling the component will restore the original mesh instead). Mesh's normal and tangent vectors can optionally be recalculated in one of two ways:
34-
-- Modify Originals: the original mesh's normal and tangent vectors will be rotated with the spline
35-
-- Recalculate From Scratch: Unity's RecalculateNormals and/or RecalculateTangents functions will be invoked to recalculate these vectors from scratch
36-
Note that this component doesn't add new vertices to the original mesh, so if the original mesh doesn't have enough vertices in its bend axis, then the bent mesh will have jagged edges on complex splines.
3+
Documentation: https://github.com/yasirkula/UnityBezierSolution
4+
E-mail: yasirkula@gmail.com

Plugins/BezierSolution/Utilities/BezierWalker.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace BezierSolution
55
{
66
public enum TravelMode { Once = 0, Loop = 1, PingPong = 2 };
7-
public enum LookAtMode { None = 0, Forward = 1, SplineExtraData = 2 }
7+
public enum LookAtMode { None = 0, XForward = 3, YForward = 4, ZForward = 1, SplineExtraData = 2 }
88

99
public abstract class BezierWalker : MonoBehaviour
1010
{
@@ -26,10 +26,17 @@ protected void RotateTarget( Transform target, float normalizedT, LookAtMode loo
2626
Quaternion targetRotation;
2727
switch( lookAt )
2828
{
29-
case LookAtMode.Forward:
29+
case LookAtMode.XForward:
30+
case LookAtMode.YForward:
31+
case LookAtMode.ZForward:
3032
{
3133
BezierSpline.Segment segment = Spline.GetSegmentAt( normalizedT );
3234
targetRotation = Quaternion.LookRotation( MovingForward ? segment.GetTangent() : -segment.GetTangent(), segment.GetNormal() );
35+
if( lookAt == LookAtMode.XForward )
36+
targetRotation *= Quaternion.Euler( 0f, -90f, 0f );
37+
else if( lookAt == LookAtMode.YForward )
38+
targetRotation *= Quaternion.Euler( 0f, 90f, 90f );
39+
3340
break;
3441
}
3542
case LookAtMode.SplineExtraData: targetRotation = Spline.GetExtraData( normalizedT, extraDataLerpAsQuaternionFunction ); break;

Plugins/BezierSolution/Utilities/BezierWalkerLocomotion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class BezierWalkerLocomotion : BezierWalker
2424
public float movementLerpModifier = 10f;
2525
public float rotationLerpModifier = 10f;
2626

27-
public LookAtMode lookAt = LookAtMode.Forward;
27+
public LookAtMode lookAt = LookAtMode.ZForward;
2828

2929
public override BezierSpline Spline { get { return walker.Spline; } }
3030

Plugins/BezierSolution/Utilities/BezierWalkerWithSpeed.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override float NormalizedT
2626
//public float movementLerpModifier = 10f;
2727
public float rotationLerpModifier = 10f;
2828

29-
public LookAtMode lookAt = LookAtMode.Forward;
29+
public LookAtMode lookAt = LookAtMode.ZForward;
3030

3131
private bool isGoingForward = true;
3232
public override bool MovingForward

Plugins/BezierSolution/Utilities/BezierWalkerWithTime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public override float NormalizedT
2828
public float movementLerpModifier = 10f;
2929
public float rotationLerpModifier = 10f;
3030

31-
public LookAtMode lookAt = LookAtMode.Forward;
31+
public LookAtMode lookAt = LookAtMode.ZForward;
3232

3333
private bool isGoingForward = true;
3434
public override bool MovingForward

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.yasirkula.beziersolution",
33
"displayName": "Bezier Solution",
4-
"version": "2.3.3",
4+
"version": "2.3.4",
55
"documentationUrl": "https://github.com/yasirkula/UnityBezierSolution",
66
"changelogUrl": "https://github.com/yasirkula/UnityBezierSolution/releases",
77
"licensesUrl": "https://github.com/yasirkula/UnityBezierSolution/blob/master/LICENSE.txt",

0 commit comments

Comments
 (0)