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: Any way to lerp linearly between two CFrames

Previous Thread :: Next Thread 
Hyperant is not online. Hyperant
Joined: 05 Apr 2013
Total Posts: 615
19 Jul 2016 08:12 PM
Yes i know i was redundant in the title but hear me out

Lets say i have this: v.Weld.C1 = Position1:lerp(Position2, x)

Let me display two cases:

I) A part is shifted by 30"
II) Another part is shifted by 60"

How can i make it so that in both cases, the parts shift by a constant unit when lerping?
Report Abuse
sentry3 is not online. sentry3
Joined: 01 May 2010
Total Posts: 538
19 Jul 2016 08:15 PM
are you saying how to make them do it at the same time? if so use coroutines
http://wiki.roblox.com/index.php/Beginners_Guide_to_Coroutines
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
19 Jul 2016 08:15 PM
local part = script.Parent
local start = script.Start.CFrame
local fin = script.Finish.CFrame

local t = 30
local delta = 0

for i = 1, 100 do
part.CFrame = start:lerp(fin, i/100)
delta = (t/100+delta)-wait(t/100+delta)
end
Report Abuse
Hyperant is not online. Hyperant
Joined: 05 Apr 2013
Total Posts: 615
19 Jul 2016 08:28 PM
@sentry3 Thats not what i meant. What i meant was in lerp, if the two positions are either close or far apart, i want them to lerp at a constant rate.

@warspyking

I don't think that will be very effective since what I'm using isn't quite compatible with your's.

Is there a way to do this task without the use of your mentioned loop
Report Abuse
RemasteredBox is not online. RemasteredBox
Joined: 19 Jun 2016
Total Posts: 2140
19 Jul 2016 08:42 PM
Make a lerping function then when you need it to be synchronized just wrap it in a coroutine.


#code print("While I may look like a cataclysmic god of the eggs from the future, I am not.")
Report Abuse
Hyperant is not online. Hyperant
Joined: 05 Apr 2013
Total Posts: 615
19 Jul 2016 09:58 PM
Hmm so what if the coroutine is continuous?
Report Abuse
RemasteredBox is not online. RemasteredBox
Joined: 19 Jun 2016
Total Posts: 2140
19 Jul 2016 10:14 PM
Your going to have to be more specific by "continuous", I can think of a million things you could mean by that.


#code print("While I may look like a cataclysmic god of the eggs from the future, I am not.")
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
19 Jul 2016 10:17 PM
My code works perfectly fine for lerping a CFrame between 2 others, it's just I used parts to give a visual aid on how it worked.
Report Abuse
Hyperant is not online. Hyperant
Joined: 05 Apr 2013
Total Posts: 615
19 Jul 2016 10:26 PM
@Remastered

I meant that its in a continuous 'while true do' loop.

Maybe i should be just a little more visual.

x = Start
y = Final

In this case it is a normal lerp
x . . . . y
x . . . . y

However what im trying to do is making it more like this
x . . . . y
x . . . . . . . . . . y
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
19 Jul 2016 10:32 PM
'In this case it is a normal lerp
x . . . . y
x . . . . y

However what im trying to do is making it more like this
x . . . . y
x . . . . . . . . . . y'


That makes 0 sense. Normal lerp, where x lerps to y:

x..........y
.x.........y
..x........y
...x.......y
....x......y
.....x.....y
......x....y
.......x...y
........x..y
.........x.y
..........xy
Report Abuse
baa_aaa is not online. baa_aaa
Joined: 18 Nov 2015
Total Posts: 491
19 Jul 2016 10:37 PM
You just need to control your x differently. I'm assuming right now you're lerping by a constant amount each frame, but you should really try this:

for i = 0, 1, 1/60 do
game:GetService("RunService").Heartbeat:wait()
v.Weld.C1 = cf1:lerp(cf2, i)
end
Report Abuse
Hyperant is not online. Hyperant
Joined: 05 Apr 2013
Total Posts: 615
19 Jul 2016 10:48 PM
What i showed there was a side by side comparison

More explanation time.

Lets have two bricks, A and B. The two bricks are at the origin which is 0,0,0

A wants to 10,0,0 while B wants to go to 20,0,0

Assuming normal lerping would be this.

Start = 0,0,0
AGoal = 10,0,0
BGoal = 20,0,0

for i=1,10 do
A.Position = Start:lerp(AGoal, i/20) --Moves by one stud a second
B.Position = Start:lerp(BGoal, i/20) --Moves by two studs a second
wait(1)
end

What i want is so that both bricks move at the same rate of one stud a second.
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
19 Jul 2016 11:04 PM
"you're lerping by a constant amount each frame, but you should really try this"
> proceeds to doing the exact same thing
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
19 Jul 2016 11:04 PM
oh wait u used heartbeat
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
19 Jul 2016 11:45 PM
2 separate scripts:


local part = workspace.Apart
local start = script.AStart.CFrame
local fin = script.AFinish.CFrame

local t = (fin.p-start.p).magnitude
local delta = 0

for i = 1, 100 do
part.CFrame = start:lerp(fin, i/100)
delta = (t/100+delta)-wait(t/100+delta)
end



local part = workspace.Bpart
local start = script.BStart.CFrame
local fin = script.BFinish.CFrame

local t = (fin.p-start.p).magnitude
local delta = 0

for i = 1, 100 do
part.CFrame = start:lerp(fin, i/100)
delta = (t/100+delta)-wait(t/100+delta)
end
Report Abuse
Hyperant is not online. Hyperant
Joined: 05 Apr 2013
Total Posts: 615
19 Jul 2016 11:55 PM
Thanks for trying but thats not i was looking for.

I shall ask again soon once i go on my own for a bit.
Report Abuse
xXIcanthinkofanameXx is not online. xXIcanthinkofanameXx
Joined: 05 May 2012
Total Posts: 857
20 Jul 2016 12:30 AM
I'm not entirely sure what you mean, but reading through your posts I think I have a pretty good idea. So to my understanding you want to be able to update multiple lerps in a single while loop. This code is only for a single lerp being updated like this, however with a bit of work you can generalize this to work for any number of lerps.

local startCF;
local endCF;--pretend startCF and endCF are not nil
local startTime;
local isLerping=false;
local lerpTime;
local currentLerpCF;--the current CFrame that is being lerped

local function startTween(start,end,time)
startTime=tick();--this is when we started lerping
lerpTime=time;
startCF=start;
endCF=end;
isLerping=true;
end;

local c=coroutine.create(function()--updates the lerp
while true do
if isLerping then
local t=(tick()-startTime)/lerpTime;--how far we are in our lerp
currentLerpCF=startCF:lerp(endCF,t);
if t>=1 then-- end the lerp, we're done.
isLerping=false;
end;
else
wait();
end;
end);
coroutine.resume(c);

I hope this helps!
Report Abuse
xXIcanthinkofanameXx is not online. xXIcanthinkofanameXx
Joined: 05 May 2012
Total Posts: 857
20 Jul 2016 12:33 AM
I always miss something when I write code in the forums. There should be a wait();
after setting currentLerpCF in the while loop.
Report Abuse
xXIcanthinkofanameXx is not online. xXIcanthinkofanameXx
Joined: 05 May 2012
Total Posts: 857
20 Jul 2016 12:58 AM
Oh you know what, scratch what I said, I'm dumb. We need to do some math here. The basic linear interpolation formula will work for our purposes:

l=a*(1-t)+bt=a+(b-a)t (equation 1)

Taking the derivative with respect to t to obtain velocity yields:

dl/dt=b-a=v (equation 2)

Now, it's obvious that the magnitude of b-a may not be equal to v, the desired velocity, so we will multiply the right side of equation 2 by c, a constant we know will scale b-a to equal v. So now this yields

dl/dt=(b-a)*c=v

And now we can rewrite equation 1 in terms of it's derivative and t, which yields

l=a+(b-a)tc

This was all remarkably simple, so now the question is what is c? Remember we defined c to be a scale factor that multiplies |b-a|*c=|v|. so solving for c is easy, c=|v|/|b-a|.

So to conclude, just multiply t by |v|/|b-a| where v is your desired velocity. I know this was a rather long response, but I just want to be sure you understand what is going on and not just how to do something, but why it works. So hopefully that made sense, and this helped.
Report Abuse
Hyperant is not online. Hyperant
Joined: 05 Apr 2013
Total Posts: 615
20 Jul 2016 05:27 PM
Wow, this will help lots. Thank you for your responses.

Now for my issue. How would i apply this to CFrames in relation to angles?
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