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 » Scripters
Home Search
 

Re: Off tweening

Previous Thread :: Next Thread 
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Sep 2012 01:28 AM
Don't tell me to use the TweenPosition method.

I have a gui that tweens using quad easing but it's never exact on duration. My method for the duration is odd, especially because roblox doesn't wait under 0.03 - 0.04 (most of the time), which is why I'm thinking that it might be impossible for my tweening to be exact, but I figure I'd ask.

Here's some code,

local duration = 10 --seconds
local frames = duration * 20

function easeInQuad(t,b,c,d)
t = t/d
return c*t*t + b
end

for frame = 0,frames do
script.Parent.Position = UDim2.new(easeInQuad(frame,0,0.9,frames),0,0)
wait(duration/frames)
end

Now, where the * 20 comes in, I don't exactly know, kind of a trial and error thing. But it's not 100% accurate, however, it's not too off (usually fractions of a second, but if the duration is higher, the accuracy differs -lowers.)

In conclusion, I was wondering if it is possible, using similar code, to have the duration exact?
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
23 Sep 2012 01:33 AM
Why exactly do we need this when we can use TweenPosition?
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Sep 2012 01:35 AM
Classified information.
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
23 Sep 2012 01:36 AM
There's a red spy in your base. Give me your information so he can't steal it.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Sep 2012 01:39 AM
I could give you the information, but then I'd have to kill you.
Report Abuse
GreenDay987 is not online. GreenDay987
Joined: 21 May 2011
Total Posts: 7027
23 Sep 2012 02:26 AM
@nate

He would just respawn...
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Sep 2012 02:28 AM
then I'd have to spawn kill him.
Report Abuse
GreenDay987 is not online. GreenDay987
Joined: 21 May 2011
Total Posts: 7027
23 Sep 2012 02:29 AM
Forcefield gives enough to for him to kill you.
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
23 Sep 2012 04:44 AM
Your tweening function is strange.

A tweening function should always be such that:

    f(0) == 0
    f(1) == 1

Here's a fixed version:

    function easeInQuad(t, slope)
        slope = slope or 1
        return (1 - slope)*t*t + slope*t
    end

    local time = 0
    while time < duration do
        time += wait()
        local t = time / duration
        script.Parent.Position = UDim2.new(start + (end - start) * easeInQuad(t, 0.1), 0, 0, 0)
    end
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Sep 2012 09:15 AM
tyvm :). Actually got the tweening funtions from http://gizma.com/easing/#cub3
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Sep 2012 09:35 AM
There's actually a slight problem with that tween. Although the duration is quite accurate (10.077206134796 for 10 seconds) the tween doesn't (Ever) finish where the ending destination is. It either passes it, or lands just before it, because the time is more than duration or duration is more than time when it shouldn't be which causes an issue
Report Abuse
SN0X is not online. SN0X
Joined: 24 Oct 2011
Total Posts: 7277
23 Sep 2012 09:37 AM
then instead of while time < duration, while pos < endpos???
didnt read anything much dont flame me pls
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Sep 2012 09:42 AM
Couldn't do that.
Report Abuse
trappingnoobs is not online. trappingnoobs
Joined: 05 Oct 2008
Total Posts: 19100
23 Sep 2012 09:45 AM
if _ ​>= endtime then return endpos

something like that should fix it for you? didn't bother reading into the algorithms so might seem like an uneducated response.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Sep 2012 09:55 AM
I don't think so, as I get the approximate time it should take to finish by dividing the duration by the frames. Which is completely hackish as the amount of frames are determined by duration * 20, which is what I from quick trial and error testing.
Report Abuse
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
23 Sep 2012 10:07 AM
something like:

restoftween()
if GUI is too far then
movetoend()
else
wait(step)
movetoend()
end
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Sep 2012 10:11 AM
prehistoric, that's results in ugly tweening. It'll jump passed then end and then suddenly jump to the end. In my opinion, tweening should be smooth; this would not be smooth.
Report Abuse
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
23 Sep 2012 10:14 AM
You dun understand.


move the object
check if it is too far
move it back if it is
end of tween

no waits so no jumping
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Sep 2012 10:15 AM
oh, i might try that, but still something that i'm not enthusiastic about doing.
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
23 Sep 2012 10:20 AM
Simple fix:

    function tweener(f)
        return function(t, ...)
            if t ​> 1 then t = 1 end
            if t < 0 then t = 0 end
            return f(t, ...)
        end
    end

    easeInQuad = tweener(function(t, slope)
        slope = slope or 1
        return (1 - slope)*t*t + slope*t
    end)
    
    local time = 0
    while time < duration do
        time += wait()
        local t = time / duration
        script.Parent.Position = UDim2.new(start + (end - start) * easeInQuad(t, 0.1), 0, 0, 0)
    end

Just add a function that clamps the inputs of the tweening function. You don't want to clamp the outputs, else you can't do any kind of "bouncing" tweens.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Sep 2012 10:23 AM
very nice'a. ty
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
23 Sep 2012 10:23 AM
> Actually got the tweening funtions from...

Oh, I see. I'm thinking of a different form of the functions. I was thinking `start + (end - start) * tween(t)`, rather than `tween(t, start, end)`. Either works. Mine would be useful in a case such as:

    a:lerp(b, cubicTween(t))

to lerp vectors cubically.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Sep 2012 10:27 AM
Is there a way to fix the issue I'm having with my particular tweens?
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
23 Sep 2012 10:31 AM
Wait, what's the problem? I thought I fixed the two problems you were having (goes past the end, duration unreliable)
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Sep 2012 10:34 AM
"I was thinking `start + (end - start) * tween(t)`, rather than `tween(t, start, end)`."

So they are two different tweens... meaning that "Your tweening function is strange." was because of a misunderstanding, that lead to you to coding a whole new one.

Out of learning sakes, how could I have fixed my original problem: duration because quite off with my original code?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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