3

I am working on a game in which a butterfly is flying along some path.

What I am trying to do currently is create a Bezier curve starting from the butterfly's position(previous curves end point) and the rest of the points random for it to fly on. Once it has finished on the curve it needs to continue its path along the next curve that is generated. The problem I have is that the next curve sometimes starts in a direction that makes the transition look rugged and unrealistic. This is the code I have so far.

void updateDirection()
{
    if (!LeanTween.isTweening(this.gameObject))
    {
        Vector3 curveA = { transform.position, new Vector3(Random.Range(-5f, 0), 0, Random.Range(-3f, 0)), new Vector3(Random.Range(-5f, 0), 0, Random.Range(-3f, 0)), new Vector3(Random.Range(-5f, 0), 0, Random.Range(-3f, 0)) };
        LeanTween.move(this.gameObject, curveA, 3f);
    }
}

I am using the LeanTween API to create the movement method easier.

So basically I need to find a way to make a continuous bezier I guess and I am no mathematician so if it could be explained in easy to understand terms that would be amazing!

2 Answers2

1

You will probably have an easier time with a catmul rom spline. You give points for the path to pass through and it figures out the rest. A catmul rom spline is a type of Hermite spline, which is a different mathematical form of bezier splines. http://www.mvps.org/directx/articles/catmull/

Alan Wolfe
  • 2,353
  • 1
  • 13
  • 30
0

I guess you could use a trail system much like the one provided for a similar problem:How to approach 360 degree snake without having it "slide"

if you can get the transform of every point of your splines (all of them) you can then add them to a List and use the trail system to traverse them.

Thaon
  • 11
  • 1