generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Sine Interpolation

Previous Thread :: Next Thread 
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
07 Oct 2013 05:26 PM
How would I make this CFrame interpolation loop start slowly and finish slowly? My feeling is that the variable t needs to be changed, but I don't know how to go about doing this. Any help is greatly appreciated.

while true do
wait()
if go then return false end
local t = (tick()-startTime)/length
local _t = 1-t
if t > 1 then weld.C1 = b return true end
local startT = tick()
local cf = QuaternionToCFrame(_t*ax + t*bx, _t*ay + t*by, _t*az + t*bz,
QuaternionSlerp(qa, qb, t))
tot = tot+(tick()-startT)
c = c + 1
weld.C1 = cf
end
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
07 Oct 2013 05:31 PM
parabola
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
07 Oct 2013 05:45 PM
Why am I so dumb...

So obviously I could just do t = t ^ 2

but how would I get it to also start slowly at the beginning?
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
07 Oct 2013 05:49 PM
id use a 3rd variable, position in essences, then use the parabola as the change in position. that way, at the begging, it moves slowly, and at the end it moves slowly.
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
07 Oct 2013 06:12 PM
Unless I didn't understand that correctly, I don't think a parabola would work because it would start from the end, move back to the beginning, and then move to the end again because that is the shape of a parabola.
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
07 Oct 2013 06:52 PM
Okay so this works, but I feel like it is way over complicating things so if anybody has an easier way I would love to hear it.

if t < .5 then
t = 2*t^2
elseif t <= 1 then
t = (.5-(2*(.5 - (t - .5))^2))+.5
end
Report Abuse
MHebes is not online. MHebes
Joined: 04 Jan 2013
Total Posts: 2278
07 Oct 2013 07:10 PM
If you have a linear variable t, you can use a sine wave, translated and stretched to fit in the correct domain (0-1) and range (also 0-1):

function GetSmooth(x) return math.sin((x-0.5)*math.pi)/2+0.5 end
for i = 0,1,0.1 do print(GetSmooth(i)) end

To visualize this, go to this website:
mathopenref [dot] com/graphfunctions [dot] html
and put this as one function:
sin((x-0.5)*pi)/2+0.5
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
07 Oct 2013 07:15 PM
yay, i get to use the math i just learned in school today

function Get_Smooth_Position(x,max_x,max_y)
local XVALUE = 4.3
local YVALUE = 34
local max_x = 1/max_x*XVALUE
local max_y = 1/YVALUE*max_y
local x = x*max_x
local y = -.2*x^4+x^3+x^2+x+0
local y = y*max_y
return max_y
end

This should make smooth transition of movement, using a quartic parabola.

Usage:

for i = 0,500 do
wait()
print(Get_Smooth_Position(i,500,400))
end


where 500 is the max i, and 400 is as high as the y value will be.

Report Abuse
MHebes is not online. MHebes
Joined: 04 Jan 2013
Total Posts: 2278
07 Oct 2013 07:21 PM
Well, now I feel like I need to have a out of thing too:

function GetSmooth(x, out_of) return math.sin(((x/out_of)-0.5)*math.pi)/2+0.5 end

Done :D
Report Abuse
MHebes is not online. MHebes
Joined: 04 Jan 2013
Total Posts: 2278
07 Oct 2013 07:39 PM
Oh, also, I see you're doing quaternion interpolation. I've got an example of that at my place if you want to check it out :D
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
07 Oct 2013 07:53 PM
i have no idea what quaternion interpolation is... I just guessed and checked pretty much to make that script...
Report Abuse
MHebes is not online. MHebes
Joined: 04 Jan 2013
Total Posts: 2278
07 Oct 2013 08:13 PM
Sorry, was talking to OP.
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
07 Oct 2013 08:15 PM
sorry, thought you were talking to me since on the comment above you were talking about the function i made, my bad.
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
07 Oct 2013 08:45 PM
Thanks a bunch guys I will be sure to test with all of that stuff.

And the interpolation looks nice hebes!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image