How to do spline motion?

This forum is for discussing shmup development, tools, engines and techniques.
Posts: 11
Joined: Wed Nov 02, 2016 2:52 am

How to do spline motion?

Postby xmzhang » Mon Nov 28, 2016 7:45 am

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
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))

Site Admin
User avatar
Posts: 240
Joined: Thu Jul 26, 2012 2:32 pm
Location: Melbourne

Re: How to do spline motion?

Postby monoRAIL » Mon Nov 28, 2016 10:22 am

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

User avatar
Posts: 42
Joined: Thu Mar 26, 2015 2:37 am

Re: How to do spline motion?

Postby lzardo » Sat Dec 03, 2016 1:39 am

I´m using this one:

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

You can try my latest techdemo on the showcase section.

Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest