NotAshley
|
  |
| Joined: 16 Jan 2014 |
| Total Posts: 14257 |
|
|
| 03 Mar 2015 05:14 AM |
I just learned about cosine/sine math recently and spend the past few hours messing with this and finally coming up with a result.
In stravant's CFrame interpolation function, paste this as the first line of the function it returns at the bottom:
t = ((-(math.cos(t * math.pi)) * .5) - .5) - (-1)
The function's returned position will then depend on cosine math based on the number from 0 to 1. I'm not sure if I did anything wrong or if there was a quicker route, but it took a lot of experimenting and messing with and now it works.
Here's stravant's CFrame interpolation function. You give it two CFrames and it returns both an angle difference and another function, which returns the CFrame between the first two based on a 0 to 1 number, just like normal lerp.
local strav_fromAxisAngle = CFrame.fromAxisAngle local strav_components = CFrame.new().components local strav_inverse = CFrame.new().inverse local strav_v3 = Vector3.new local strav_acos = math.acos local strav_sqrt = math.sqrt local strav_invroot2 = 1/math.sqrt(2) local interpolate = function(c0, c1) local _, _, _, xx, yx, zx, xy, yy, zy, xz, yz, zz = strav_components(strav_inverse(c0)*c1) local cosTheta = (xx + yy + zz - 1)/2 local rotationAxis = strav_v3(yz-zy, zx-xz, xy-yx) local positionDelta = (c1.p - c0.p) local theta; if cosTheta >= 0.999 then return 0, function(t) return c0 + positionDelta*t end elseif cosTheta <= -0.999 then theta = math.pi xx = (xx + 1) / 2 yy = (yy + 1) / 2 zz = (zz + 1) / 2 if xx > yy and xx > zz then if xx < 0.001 then rotationAxis = strav_v3(0, strav_invroot2, strav_invroot2) else local x = strav_sqrt(xx) xy = (xy + yx) / 4 xz = (xz + zx) / 4 rotationAxis = strav_v3(x, xy/x, xz/x) end elseif yy > zz then if yy < 0.001 then rotationAxis = strav_v3(strav_invroot2, 0, strav_invroot2) else local y = strav_sqrt(yy) xy = (xy + yx) / 4 yz = (yz + zy) / 4 rotationAxis = strav_v3(xy/y, y, yz/y) end else if zz < 0.001 then rotationAxis = strav_v3(strav_invroot2, strav_invroot2, 0) else local z = strav_sqrt(zz) xz = (xz + zx) / 4 yz = (yz + zy) / 4 rotationAxis = strav_v3(xz/z, yz/z, z) end end else theta = strav_acos(cosTheta) end return theta, function(t) --The cosine math goes here return c0*strav_fromAxisAngle(rotationAxis, theta*t) + positionDelta*t end end |
|
|
| Report Abuse |
|
|
NotAshley
|
  |
| Joined: 16 Jan 2014 |
| Total Posts: 14257 |
|
| |
|
| |
|
Tuneable
|
  |
| Joined: 16 Feb 2013 |
| Total Posts: 2932 |
|
|
| 03 Mar 2015 04:58 PM |
| I don't understand what the point is in doing this. Example? |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2015 04:59 PM |
| ^ UR A HORSE NO LOGIC APPLIES WHAT IS A COSINE HAPILATEOR FUNCTION THING |
|
|
| Report Abuse |
|
|
NotAshley
|
  |
| Joined: 16 Jan 2014 |
| Total Posts: 14257 |
|
|
| 03 Mar 2015 05:02 PM |
"I don't understand what the point is in doing this. Example?"
It's for you're using stravant's function for making CFrame/weld animations. You use it exactly like you would, but it uses cosine math to smooth the start and stop of the animation. |
|
|
| Report Abuse |
|
|
Tuneable
|
  |
| Joined: 16 Feb 2013 |
| Total Posts: 2932 |
|
|
| 03 Mar 2015 05:10 PM |
| Still don't understand why a function for right triangles is being used like this. I better go do some research |
|
|
| Report Abuse |
|
|
NotAshley
|
  |
| Joined: 16 Jan 2014 |
| Total Posts: 14257 |
|
|
| 03 Mar 2015 05:25 PM |
Imagine a point moving around a circle at a steady pace. As the point moves closer to the top of the circle, the speed the point is moving up Y axis will gradually slow down until the top. Then it'll start to decrease and get faster until the point reaches the middle of the circle, and slow down again as it reaches the bottom, and repeat.
This smooth start/stop can be used with a for loop by dividing with math.pi/2 to interpolate a number where the speed increases, reaches the middle point, then slows down to a stop. Animations can be made with this smoothing. That's what this does. |
|
|
| Report Abuse |
|
|
anaIyze
|
  |
| Joined: 29 May 2014 |
| Total Posts: 2048 |
|
| |
|
NotAshley
|
  |
| Joined: 16 Jan 2014 |
| Total Posts: 14257 |
|
|
| 03 Mar 2015 05:28 PM |
| @anaIyze thanks for the constructive criticism |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2015 05:30 PM |
Very nice! I think I'd prefer quadratic easing, but this is fine. :p
Would you mind if I threw this into a function library I'm working on? If it ever gets released, I will ensure to credit both yourself and Stavant for this. |
|
|
| Report Abuse |
|
|
NotAshley
|
  |
| Joined: 16 Jan 2014 |
| Total Posts: 14257 |
|
|
| 03 Mar 2015 05:32 PM |
| @Spirographic thanks, and sure, go ahead! I'd really be interested in this function library of yours if it's public |
|
|
| Report Abuse |
|
|
anaIyze
|
  |
| Joined: 29 May 2014 |
| Total Posts: 2048 |
|
|
| 03 Mar 2015 05:32 PM |
not u @NotAshley @above; -_- .. |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2015 05:35 PM |
Thanks! And the library isn't too much to write home about.
I'm basically just tossing a bunch of useful functions like Interpolation, screen flashes, sound effects, music management, etc in to make my life a bit easier. |
|
|
| Report Abuse |
|
|
NotAshley
|
  |
| Joined: 16 Jan 2014 |
| Total Posts: 14257 |
|
|
| 03 Mar 2015 05:37 PM |
| @Spirographic that sounds like exactlyyyy the kind of thing I'd find useful |
|
|
| Report Abuse |
|
|
anaIyze
|
  |
| Joined: 29 May 2014 |
| Total Posts: 2048 |
|
|
| 03 Mar 2015 05:38 PM |
| @above; You should look into creating beter tweening functions for parts, animating, welding, cframing, bodymovers, physical stuff (like rope, trees, etc; all that stuff that pertains to using advanced interpolation w cframe, both 2d & 3d) etc. |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2015 05:43 PM |
@Ana well, my CFrame function right now is just standard variable interpolation which can only handle Vector3s and floats by default. What's fancy about it so far however is the fact that you can choose between different easing equations such as linear(none) quadratic(basic easing) and sinusodial(one line code with easing). I'm hoping to throw more equations in there for different effects like bouncing and the like, and give it support for different variable types such as CFrames, UDim2s, etc. |
|
|
| Report Abuse |
|
|
anaIyze
|
  |
| Joined: 29 May 2014 |
| Total Posts: 2048 |
|
| |
|
|
| 05 Mar 2015 07:53 PM |
| lol nerd scrubs i bet u idiOTS dont even have gfs like me LOL |
|
|
| Report Abuse |
|
|
|
| 05 Mar 2015 08:04 PM |
@CoolioTree This is the kind of behavior that results in suicide, troubled lives, and unneeded cutting. Go rethink your life.
http://www.roblox.com/Forum/ShowPost.aspx?PostID=157128458 |
|
|
| Report Abuse |
|
|
Diitto
|
  |
| Joined: 08 Mar 2011 |
| Total Posts: 92 |
|
|
| 07 Mar 2015 05:01 PM |
ashley noob you could've just used the interpolation formula to get basis ana noob lrn2cframe scrub |
|
|
| Report Abuse |
|
|
NotAshley
|
  |
| Joined: 16 Jan 2014 |
| Total Posts: 14257 |
|
|
| 07 Mar 2015 09:46 PM |
| @Diitto try re-typing in a comprehensible and literate way and maybe I'll have a chance of understanding what you just said. |
|
|
| Report Abuse |
|
|
TheOsiris
|
  |
| Joined: 30 May 2010 |
| Total Posts: 4534 |
|
| |
|