|
| 19 Jan 2016 12:21 AM |
I want to make a script that makes the camera of the player slowly tween to a specified coordinate. For example, there is a part in workspace called PointOfView and I want the camera to tween to that part's CFRame.
Could anyone show me how this is done and how it works? |
|
|
| Report Abuse |
|
|
FPSPwnz0r
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 2737 |
|
|
| 19 Jan 2016 01:31 AM |
DoogleFox has an open source camera panner thingy in his places that could help you
idk though
|
|
|
| Report Abuse |
|
|
|
| 19 Jan 2016 01:42 AM |
Interplation.
#Code print("Song Link: http://www.roblox.com/Deorro-vs-Swedish-House-Mafia-Save-The-5-Hours-item?id=340827217") |
|
|
| Report Abuse |
|
|
|
| 19 Jan 2016 01:43 AM |
Interpolation* is basically camera tweening
#Code print("Song Link: http://www.roblox.com/Deorro-vs-Swedish-House-Mafia-Save-The-5-Hours-item?id=340827217") |
|
|
| Report Abuse |
|
|
|
| 19 Jan 2016 03:41 AM |
| There is an API :Interpolate(endpos,endfocus,duration) for Camera, but it doesn't seem to work very well. All it does is it moves towards the part, and then the screen completely goes white. |
|
|
| Report Abuse |
|
|
|
| 19 Jan 2016 07:08 AM |
Your screen goes white (normally) because you're setting endpos and endfocus to the same value. The camera interpolate method seems a little odd anyway since it floats to the end position then suddenly 'snaps' to face the end focus at the last second. So an alternative to the camera interpolate method could just be to manually interpolate it with the cframe lerp method: http://wiki.roblox.com/index.php?title=CFrame |
|
|
| Report Abuse |
|
|
|
| 19 Jan 2016 07:25 AM |
| I never did the lerp before. How would this work? |
|
|
| Report Abuse |
|
|
|
| 19 Jan 2016 07:47 AM |
lerp needs your initial and final cframe value, plus a number between 0 and 1 to dictate the 'progression' from the initial cframe to the second (wiki can explain this far better than me). So you'll want to lerp both your coordinateframe and your focus simultaneously, something like this;
local duration = 1 local elapsed = 0 repeat local dt = game:GetService("RunService").RenderStepped:wait() elapsed = math.min(elapsed+dt,duration) camera.CoordinateFrame = original:lerp(final,elapsed/duration) until elapsed >= duration |
|
|
| Report Abuse |
|
|
|
| 19 Jan 2016 09:39 AM |
Just editing what was put above by 0supadude, as there is ways of making the code he posted alot more efficent
local function Tween(Weld,Goal,Time) local Start = tick() local a = 0
repeat local Percent = min(1,(tick()-Start)/Time) a = a+(Percent-a)*.25 Weld = lerp(Initial,Goal,a) stepped:wait() until a == 1 end
In this context weld would be camera, so you run: Tween(camera.CoordinateFrame,goal,time) time is the length in seconds |
|
|
| Report Abuse |
|
|
|
| 19 Jan 2016 09:48 AM |
oops forgot to add:
local cf = CFrame.new
local function lerp(a,b,d) return a:lerp(b,d) end |
|
|
| Report Abuse |
|
|
|
| 19 Jan 2016 07:55 PM |
How is that more efficient?
Not being snarky, genuinely asking
|
|
|
| Report Abuse |
|
|