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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Best way to recreate TweenPosition method for parts?

Previous Thread :: Next Thread 
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
10 Jul 2014 01:19 PM
Or has someone already made a tween function/method for parts?

Anyways, how would I tackle this problem?
Report Abuse
129K is not online. 129K
Joined: 23 Aug 2011
Total Posts: 19010
10 Jul 2014 01:23 PM
"Or has someone already made a tween function/method for parts?"

No duh.
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
10 Jul 2014 01:24 PM
I'm thinking about using lerp method and getting alpha via sin/cos/tan.

Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
10 Jul 2014 01:29 PM
ok nvm
Report Abuse
lateregistration is not online. lateregistration
Joined: 02 Apr 2013
Total Posts: 2630
10 Jul 2014 03:55 PM
QUATERNIONS
Report Abuse
Pythonista69Rubyist is not online. Pythonista69Rubyist
Joined: 09 Jul 2014
Total Posts: 16
10 Jul 2014 04:45 PM
yep, Crazyman32 wrote a tweening library which has more than what ROBLOX has, or if you still need better there are a few on github
Report Abuse
bohdan77 is not online. bohdan77
Joined: 10 Aug 2008
Total Posts: 7944
10 Jul 2014 05:03 PM
Eh, but ROBLOX doesn't have a tweening library...so anything would be better?
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
10 Jul 2014 05:52 PM
Well the best way would be this, this was written by stravant in a RBXDev thread
This is a modulescript btw



-- Optimized CFrame interpolator module ~ by Stravant
-- Based off of code by Treyreynolds posted on the Roblox Developer Forum

local fromAxisAngle = CFrame.fromAxisAngle
local components = CFrame.new().components
local inverse = CFrame.new().inverse
local v3 = Vector3.new
local acos = math.acos
local sqrt = math.sqrt
local invroot2 = 1/math.sqrt(2)

return function(c0, c1) -- (CFrame from, CFrame to) -> (float theta, (float fraction -> CFrame between))
-- The expanded matrix
local _, _, _, xx, yx, zx,
xy, yy, zy,
xz, yz, zz = components(inverse(c0)*c1)

-- The cos-theta of the axisAngles from
local cosTheta = (xx + yy + zz - 1)/2

-- Rotation axis
local rotationAxis = v3(yz-zy, zx-xz, xy-yx)

-- The position to tween through
local positionDelta = (c1.p - c0.p)

-- Theta
local theta;

-- Catch degenerate cases
if cosTheta >= 0.999 then
-- Case same rotation, just return an interpolator over the positions
return 0, function(t)
return c0 + positionDelta*t
end
elseif cosTheta <= -0.999 then
-- Case exactly opposite rotations, disambiguate
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 = v3(0, invroot2, invroot2)
else
local x = sqrt(xx)
xy = (xy + yx) / 4
xz = (xz + zx) / 4
rotationAxis = v3(x, xy/x, xz/x)
end
elseif yy > zz then
if yy < 0.001 then
rotationAxis = v3(invroot2, 0, invroot2)
else
local y = sqrt(yy)
xy = (xy + yx) / 4
yz = (yz + zy) / 4
rotationAxis = v3(xy/y, y, yz/y)
end
else
if zz < 0.001 then
rotationAxis = v3(invroot2, invroot2, 0)
else
local z = sqrt(zz)
xz = (xz + zx) / 4
yz = (yz + zy) / 4
rotationAxis = v3(xz/z, yz/z, z)
end
end
else
-- Normal case, get theta from cosTheta
theta = acos(cosTheta)
end

-- Return the interpolator
return theta, function(t)
return c0*fromAxisAngle(rotationAxis, theta*t) + positionDelta*t
end
end

Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
10 Jul 2014 10:42 PM
I made one using coroutines and global functions a while back. It basically implements a tweening function into your game, and handles CFrame as well as angles:

http://www.roblox.com/Part-Tweening-Service-item?id=67222290
Report Abuse
TigreBlood is not online. TigreBlood
Joined: 31 Jul 2011
Total Posts: 1107
11 Jul 2014 07:15 AM
zzz .l. coroutine's to laggy noob !
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
11 Jul 2014 09:13 AM
@Tigre
Right, my PC is probably way better than yours.

Really though, I ran that on my 6 year old craptop without lag.
Report Abuse
DrunkerScripter is not online. DrunkerScripter
Joined: 22 Jun 2013
Total Posts: 275
11 Jul 2014 11:31 AM
I remember having a function like that, hold on.

function movePart(part, posx, posy)
    part.CFrame = CFrame.new(Vector3.new(posx.X.Scale, posy.Y.Scale, posx.Y.Scale))
end

function tweenPart(part, endPosition, dir, style, time)
    local frameXZ = Instance.new("Frame")
    local frameY = Instance.new("Frame")
    frameXZ.Parent = gui
    frameY.Parent = gui
    frameXZ.Position = UDim2.new(part.Position.X, 0, part.Position.Z, 0)
    frameY.Position = UDim2.new(0, 0, part.Position.Y, 0)
    frameXZ:TweenPosition(UDim2.new(endPosition.X, 0, endPosition.Z, 0), dir, style, time+.5)
    frameY:TweenPosition(UDim2.new(0, 0, endPosition.Y, 0), dir, style, time+.5)
    while wait() do
        movePart(part, frameXZ.Position, frameY.Position)
        if (frameXZ.Position.X.Scale == endPosition.X) and (frameXZ.Position.Y.Scale == endPosition.Z) and (frameY.Position.Y.Scale == endPosition.Y) then
            break
        end
    end
    part.Position = endPosition
    frameXZ:Destroy()
    frameXZ = nil
    frameY:Destroy()
    frameY = nil
    part = nil
end

tweenPart(Workspace.Part,Vector3.new(0,10,0),"Out","Linear",3)

Something like that
Report Abuse
Xeptix is online. Xeptix
Joined: 14 Mar 2013
Total Posts: 1115
11 Jul 2014 12:07 PM
@above

didn't work correctly, so I edited it up a bit and published it as a module.

http://www.roblox.com/TweenPart-function-item?id=165821246
Report Abuse
DrunkerScripter is not online. DrunkerScripter
Joined: 22 Jun 2013
Total Posts: 275
11 Jul 2014 12:29 PM
Oops (facepalm)

There is meant to be a line above the first function saying

local gui = Instance.new("ScreenGui",script)
Report Abuse
dogwarrior24 is not online. dogwarrior24
Joined: 10 Nov 2010
Total Posts: 1401
11 Jul 2014 02:18 PM
@tigre
Coroutines don't lag unless your doing something idiotic like running 5 while true do loops with 5 different coroutines.
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
11 Jul 2014 02:22 PM
At most, my script runs 2 coroutines with 6 while true do loops.
Report Abuse
TigreBlood is not online. TigreBlood
Joined: 31 Jul 2011
Total Posts: 1107
11 Jul 2014 02:23 PM
zzz .l. to mani coroutine lag mi game up to much to stop usin coroutien's and make no coroutine
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
11 Jul 2014 02:25 PM
Oops, I meant at most it runs 6 coroutines each containing a single for loop.
Report Abuse
TigreBlood is not online. TigreBlood
Joined: 31 Jul 2011
Total Posts: 1107
11 Jul 2014 05:32 PM
.l.
Report Abuse
18cwatford is not online. 18cwatford
Joined: 08 Oct 2009
Total Posts: 5410
11 Jul 2014 05:43 PM
The previously posted script by stravant is actually a module he's published and has publicized as a reply to a few threads (both on RBXDev and Scripters).

http://www.roblox.com/CFrameInterpolator-Module-item?id=161739700
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