## How to do spline motion?

3 posts
• Page

**1**of**1**### How to do spline motion?

well, I meet a problem on spline motion, I read the old tutorial http://cokane.com/shmupdevarchive/index.php?PHPSESSID=LcsdAcuVBwpBpYMHZ6JhE3&topic=1638.0. However, due to my poor English and understanding, I sucked at smooth motion. I can get the spline curve by the following code

however, how to calculate the arc length? In tutorial, the author said using the formula

well, I am lost here. I can get the spline curve point (x0,y0),(x1,y1)... by the spline curve code, but how to calculate the t? a is an any value I can set ? and how about a0 , a1, a0 = sqrt(x0**2 + y0**2) or not? and t1 - t0 is not constant?

I did some tries, but failed, I must calculate the t, then I can use the code?

- Code: Select all
`x = 0.5 * ((2 * p1x) + (p2x - p0x)*t + (2*p0x - 5*p1x + 4*p2x - p3x)*t*t + (3*p1x + p3x - p0x - 3*p2x)*t*t*t)`

y = 0.5 * ((2 * p1y) + (p2y - p0y)*t + (2*p0y - 5*p1y + 4*p2y - p3y)*t*t + (3*p1y + p3y - p0y - 3*p2y)*t*t*t)

however, how to calculate the arc length? In tutorial, the author said using the formula

- Code: Select all
`t = t0 + ((a - a0) / (a1 - a0)) * (t1 - t0)`

well, I am lost here. I can get the spline curve point (x0,y0),(x1,y1)... by the spline curve code, but how to calculate the t? a is an any value I can set ? and how about a0 , a1, a0 = sqrt(x0**2 + y0**2) or not? and t1 - t0 is not constant?

I did some tries, but failed, I must calculate the t, then I can use the code?

- Code: Select all
`dx = 0.5 * (p2x - p0x + 2*t*(2*p0x - 5*p1x + 4*p2x - p3x) + 3*t*t*(3*p1x + p3x - p0x - 3*p2x))`

dy = 0.5 * (p2y - p0y + 2*t*(2*p0y - 5*p1y + 4*p2y - p3y) + 3*t*t*(3*p1y + p3y - p0y - 3*p2y))

### Re: How to do spline motion?

Are you using the Unity engine? If so, instead of solving curve equations in your code, you can simply use an editor extension like Lean Tween to draw curves and have objects follow the paths with whatever speed or interpolation settings you like.

https://www.assetstore.unity3d.com/en/#!/content/9455

https://www.assetstore.unity3d.com/en/#!/content/9455

### Re: How to do spline motion?

I´m using this one:

https://www.assetstore.unity3d.com/en/#!/content/617

You can try my latest techdemo on the showcase section.

https://www.assetstore.unity3d.com/en/#!/content/617

You can try my latest techdemo on the showcase section.

3 posts
• Page

**1**of**1**### Who is online

Users browsing this forum: No registered users and 1 guest