Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED]CFrame help for camera interpolation?

Asked by
Rheines 661 Moderation Voter
5 years ago
Edited 5 years ago

This question has been solved by the original poster.

I would like some help with interpolating my camera. I'm currently creating a dialog GUI where it would interpolate the camera looking to the position of the person I am talking with. Currently, I base the position of the camera by 2x the distance of the person and my own character using :Lerp. This works fine unless the player speaks to the person at a very close distance (touching distance), where my player would not be able to be seen. This is a GIF of it:

https://gyazo.com/ffc136ea6220fce2200450c1e4c3af77

This is my current code:

function dialog:FocusTo(position)
    CurrentCamera.CameraType = Enum.CameraType.Scriptable

    local cframe = RootPart.CFrame

    local point = position:Lerp(cframe, 2) * CFrame.new(0,4,4)
    CurrentCamera:Interpolate(point, position, 0.4)
end

I am very bad at vector maths, so what I want to do is to have the camera positioned 2x the distance between the person and the character, plus a fixed 20 studs so both the person and the character can be seen while talking. How can I add that 20 studs?

0
I am not sure why you are using Lerp? CurrentCamera:Interpolate() is all you need User#5423 17 — 5y
0
It's to get the CFrame value of twice the distance of the character and the part. Rheines 661 — 5y
0
This would just return *2 the RootPart.CFrame https://developer.roblox.com/articles/Lerp User#5423 17 — 5y
0
You can get the distance between the npc and character by using (player.Position - npc.Position).Magnitude * 2 https://developer.roblox.com/articles/Magnitude User#5423 17 — 5y
View all comments (6 more)
0
Using Lerp works too.. as evident in the GIF. Rheines 661 — 5y
0
It would stick to using the functions build for the task. Yes it is possible to do this all with lerp and the run service. User#5423 17 — 5y
0
Anyways, this is an illustration of what I want to achieve: https://gyazo.com/1fc264f260ac428a895d344425f86c61. I just need help on how to add that 20 studs. Rheines 661 — 5y
0
This is just a guess. RootPart.CFrame * CFrame.new((RootPart.CFrame.lookVector * -1) * ((RootPart.CFrame.p - npc.Position).Magnitude * 2) +20)) User#5423 17 — 5y
0
Got this error for that: 01:28:39.804 - Players.Rheines.PlayerGui.Dialog.LocalScript.Dialog:59: bad argument #2 to '?' (Vector3 expected, got number). Rheines 661 — 5y
0
I would be able to help you more in SH chat. User#5423 17 — 5y

1 answer

Log in to vote
0
Answered by
Rheines 661 Moderation Voter
5 years ago

I managed to solve it, gives me what I want:

function dialog:FocusTo(position)
    CurrentCamera.CameraType = Enum.CameraType.Scriptable

    local cframe = RootPart.CFrame

    local point = position.p:Lerp(cframe.p, 2)

    local lookAt = RootPart.CFrame.p - position.p

    local unit = lookAt.unit

    --End point, add 5 studs to the camera height.
    local endpoint = CFrame.new(point + (unit * 5)) * CFrame.new(0,5,0)

    CurrentCamera:Interpolate(endpoint, position, 0.4)
end
Ad

Answer this question