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

workspace.CurrentCamera not being updated at all when using RenderStepped In-Game?

Asked by 3 years ago
Edited 3 years ago

I wanted to make a camera animation, but I decided to take a more "unorthodox" method to say the least. Instead of using TweenService to animate the camera itself, I decided to animate a Humanoid's torso using Moon Animator because it would be easier for me to control the timing of the camera and I wouldn't have to worry about making +20 Tweens with different timing, after exporting the animation I would insert a LocalScript inside StarterPlayerScripts that would update the CFrame of the camera accordingly to the CFrame to the torso, this is the script I came up with:

local RunService = game:GetService("RunService")

workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable

local function onRenderStepUpdate(deltaTime)
    local Humanoid = workspace:WaitForChild("Humanoid")
    local Torso = Humanoid.Torso

    local ToPosition = Torso.CFrame.Position
    local ToOrientation = Torso.CFrame.LookVector

    local CamPosition = workspace.CurrentCamera.CFrame.Position
    local CamOrientation = workspace.CurrentCamera.CFrame.LookVector

    CamPosition = Vector3.new(ToPosition.X, ToPosition.Y, ToPosition.Z)
    CamOrientation = Vector3.new(ToOrientation.X, ToOrientation.Y, ToOrientation.Z)
    print("Camera Update")
end

RunService.RenderStepped:Connect(onRenderStepUpdate) -- I used RenderStepped since camera manipulation displays immediate feedback to the player.

The script doesn't work and there are no errors in the output, it prints "Camera Update" but doesn't actually move the camera in any way, the player is still able to move the camera as if the CameraType was "Custom" and not "Scriptable".

I know it is a cheap way of animating the camera but that's more comfortable to me and it allows me to have more control on the animation, I honestly don't know what's the issue here but if you do please let me know.

1
Like a cutscene? IshmaelKGaano 6 — 3y
0
No, it would be more like an In-Game loop Mordevifer 106 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago

I didn't quite understand your question but, if you are making a cutscene and trying to animate the camera, then I suggest not making the campart a humanoid, I personally make my camera a model, I put the camerapart, a rootpart to rig the camera and a torso because I don't know, then i use moon animator for the animating(of course) and i start to animate.

0
The animation itself isn't a cutscene, but rather an infinite loop that plays In-Game, it's static and only rotates in place, I'll try to follow your advice, but it doesn't solve my problem of the script not updating the CurrentCamera Position and Orientation to the Campart. Mordevifer 106 — 3y
Ad
Log in to vote
1
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

Problem

You are trying to set the Camera's position & orientation but it is not working. This is because you are never setting the camera's CFrame. You are instead setting the values of variables to new vector3 values.

Solution

Make proper assignments to the Camera's CFrame, and ensure that the Camera's type is Scriptable.

Code

-- Set Camera type
camera.CameraType = "Scriptable"

local ToPosition = Torso.CFrame.Position
local ToOrientation = Torso.CFrame.LookVector

-- The two lines below are commented out as they are not needed.
--local CamPosition = workspace.CurrentCamera.CFrame.Position
--local CamOrientation = workspace.CurrentCamera.CFrame.LookVector

workspace.CurrentCamera.CFrame = CFrame.lookAt(ToPosition, ToOrientation)

-- The two lines below are commented out as they are not needed.
--CamPosition = Vector3.new(ToPosition.X, ToPosition.Y, ToPosition.Z)
--CamOrientation = Vector3.new(ToOrientation.X, ToOrientation.Y, ToOrientation.Z)

Notes

You should use CFrame.lookAt instead of the old constructor:

Old Constructor:

CFrame.new ( Vector3 pos, Vector3 lookAt )

New Method that should be used:

CFrame.lookAt ( Vector3 at, Vector3 lookAt, Vector3 up = Vector3.new(0, 1, 0) )

The 'at' argument is the position of the CFrame. The second argument 'lookAt' is the direction the CFrame is facing (ie. the direction the camera is facing). The last argument (up) is not generally required; it is optional.

Conclusion

If you have any more questions, or anything about this answer confuses you, feel free to contact me via Discord (phxntxsmic#2021). Make sure to give some context if you contact me to make it easier.

Edit 1: Fixed Discord tag

0
I tried sending a request with your tag but it didn't seem to work, I have a small problem but I don't want to spam comments here, so try my tag instead: (Mordevifer#4971) Mordevifer 106 — 3y
0
Fixed my tag. appxritixn 2235 — 3y

Answer this question