I’m finding this tool very useful for my current project!
I found one bug in the AutoConstructSpline method (BezierSpline.cs, line 488):
endPoints[0].precedingControlPointPosition = endPoints[0].position + direction * controlPointDistance * 0.5f;
The 0.5f multiplier inappropriately shrinks the control handles of the first point of a loop spline, which warps the curve at that point. Removing the * 0.5f fixes this issue.
I’m using your bezier solution for my on-rails game. Thanks for making it, it’s fantastic! Was wondering if you could add (or point me in the direction to add myself) a way to start a follower moving from a point other than the beginning point. So if I wanted to start 50% of the way on the curve to test that part of my game, I could quickly do so?
If you are using “Once” travel mode, the fastest way would be to change “private float progress = 0f;” to “public float progress = 0f;”. Then, you can give Progress a value in range [0,1] via Inspector. Otherwise, we’d have to make a few more tweaks. Let me know in that case.
Awesome asset!!
I have assigned a sprite and box collider so that at runtime on device (not only in editor mode) the user can see and move the “Bezier Control Points”. Works well. At runtime on device the handles do not appear.
How can I assign a box collider and sprite to the handles?
Or is there another way to allow the user to adjust the handles at runtime on device (not only in editor mode)?
@jococo Thank you! You can add two empty child objects to each point of the spline with the following component attached, as well as a sprite and a box collider:
using BezierSolution;
using UnityEngine;
public class BezierCPRuntimeEditor : MonoBehaviour
{
private BezierPoint point;
private bool precedingCP;
private BezierCPRuntimeEditor otherCP;
private void Start()
{
point = transform.parent.GetComponent<BezierPoint>();
precedingCP = transform.GetSiblingIndex() == 0;
otherCP = transform.parent.GetChild( precedingCP ? 1 : 0 ).GetComponent<BezierCPRuntimeEditor>();
UpdatePosition();
}
public void UpdatePosition()
{
transform.localPosition = precedingCP ? point.precedingControlPointLocalPosition : point.followingControlPointLocalPosition;
}
// Should be called when dragged via BoxCollider
public void OnDrag()
{
if( precedingCP )
point.precedingControlPointLocalPosition = transform.localPosition;
else
point.followingControlPointLocalPosition = transform.localPosition;
otherCP.UpdatePosition();
}
}
It may not work while dragging the object in Scene view but it should work when you call OnDrag on the dragged control point (if you call both control points’ OnDrag simultaneously, one control point may always override the other; similar to what you are experiencing). Are you sure that OnDrag is only getting called for the dragged control point? Also, are you possibly calling the UpdatePosition function manually somewhere in your code?
Cool! Thanks for the tips. It seems to be working well.
I need to have the control point handles to be oriented 90degrees from created position. I’m creating a mobile app and having them oriented 90 degree offset helps with UI. Attached is a pic if that helps. Is this fairly easy code mod?
yasirkula, first of all, congratulations for the amazing job you did with this asset. Incredible!
I’m already using your asset on my project for moving sprites with curves, but I was wondering if there is a way to draw a line renderer into it. I want to draw some circles on the object’s path, so the player can know which way the object will follow, just like some baskets on Dunk Shot =)
Sorry if you’ve already explained this somewhere and I didn’t noticed!