Hello, I simply want to have the camera transition between looking at my clone’s right arm and left arm like in the video below.
Unfortunately, my code
if not game:IsLoaded() then game.Loaded:Wait() end
local h
for i,v in pairs(workspace:GetChildren()) do if v.Name == "heavenswilI" and not v:FindFirstChild("ClassicSword") and v:FindFirstChild("Humanoid") then h = v end end
print(h)
game:GetService("UserInputService").InputBegan:Connect(function(k)
if k.KeyCode == Enum.KeyCode.Z then
local t = tick()
while tick() - t < 10 do
local rightpos = CFrame.new(workspace.Camera.CFrame.Position, h["Right Arm"].Position )
workspace.Camera.CFrame = workspace.Camera.CFrame * rightpos
task.wait(2)
local leftpos = CFrame.new(workspace.Camera.CFrame.Position, h["Left Arm"].Position)
workspace.Camera.CFrame = workspace.Camera.CFrame * leftpos
end
end end)
doesn’t produce the desired effect, as you can see from the video below displaying what the code does.
I’d be happy to have someone help me on this, as I’ve been struggling with CFrames and camera manipulation for the past couple of days. I also surfed a decent amount of time through devforum but couldn’t find anything useful.
I feel like you’re getting pretty lost in the math and I think it would help if you drew a diagram of what you want to happen, showing the position of the camera, its line of sight, and the position of your character. It also looks like you are trying to animate this. I would hold off on that until you know you’re calculating the start and end points the way you want.
Thanks for the reply, azqjanna. I’m not getting lost in the math, I simply don’t know how to achieve the desired result as I couldn’t find anything similar to learn from, so, I guess I could use a link or two as well.
I don’t understand what your desired result is and most likely won’t until I see a drawing of what the movement should look like, even if its just an mspaint scribble. I cannot figure out what its supposed to look like based on the video because it looks like its a long way from being what you want.
To further describe what “position” is, in the picture below, my camera seems to also be looking at my clone’s right arm, however its “position” is different than the “position” my camera previously had.
Ok, that makes more sense. So you want the camera to switch over to your clone, and be rotated as if your clone had aimed their camera the exact same way relative to their character?
-- Get the camera
local Camera = workspace.CurrentCamera
-- Make a simple function
local function LookAt(part)
-- Make it manipulable
Camera.CameraType = Enum.CameraType.Scriptable
-- Look at it using CFrame.lookAt
Camera.CFrame = CFrame.lookAt(Camera.CFrame.Position, part.Position)
-- Allow other scripts to manipulate it again
Camera.CameraType = Enum.CameraType.Custom
end
-- Now, you can hook the following up to whatever you want:
LookAt(workspace.heavenswilI['Left Arm'])
(lag from the cursor is a roblox bug)
You could also use tweens to smooth it, like this:
local function LookAt(part)
Camera.CameraType = Enum.CameraType.Scriptable
local tween = game.TweenService:Create(
Camera,
TweenInfo.new(1),
{CFrame = CFrame.lookAt(Camera.CFrame.Position, part.Position)}
)
tween:Play()
tween.Completed:Connect(function()
Camera.CameraType = Enum.CameraType.Custom
end)
end
I would like to help a little too, but, tbh its a little confusing to understand the position, target and behaviour of the camera you want to achieve, I would ask for a drawing too as @azqjanna said
I rewatched the first video. You want your camera to toggle between between pointing directly at the clone’s left arm, to their right? What places the camera on the left arm initially? Or is the goal just to make the player camera look at one arm or the other, alternating each time the function runs?
Hi, thanks for taking the time. This was the output of the code, it’s not what I have in mind. Only at the end does it look at my clone’s right arm like I want it to (refer to my first post)
Hey. Yeah, no problem. Would you mind telling me what you want me to draw? I did my best explaining in my earlier post, so I don’t really know what to draw.
That is probably happening due to your character and the clone having the same name.
You can fix this by renaming the clone something random, and changing the “DisplayName” property of its humanoid.
Edit: Looking at the original code, I’m assuming you just put this into the while loop. You shouldn’t do that, instead, use the tween method I showed above.
As you know shift-lock has always put the camera above the right shoulder, it’s just how Roblox decided it should work, so even if you change the camera’s CFrame, the shift-lock script that manages the camera will override your changes. You’d have to fork the shift-lock camera module to make it compatible to whatever you want to achieve, it’s located somewhere under PlayerModule (StarterPlayerScripts, you have to test the game for it to appear). Or, alternatively you can use an open-sourced module made by another user (this should work), or you can just write the system yourself using CFrame.lookAt and the camera’s lookVector.