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

Trouble revolving with Camera Manipulation?

Asked by 8 years ago

Hey, guys I am trying to make a custom characterizer of my own and I am having trouble with the camera revolving around the character. So I was hoping someone could help me out with this problem I am facing right now... Here is my script I tried all sorts of different methods believe me.

local cam = workspace.CurrentCamera
local player = game.Players:GetPlayerFromCharacter(script.Parent)
local char = player.Character
local torso = char:WaitForChild("Torso")
cam.CameraSubject = torso
cam.CameraType = Enum.CameraType.Attach
local i = 0
while wait() do
cam.CFrame = cam.CFrame * CFrame.new((math.rad(i)*(math.pi*2)),0,(math.rad(i)*(math.pi*2)))
print("The math.rad*math.pi*2 number: "..(math.rad(i)*(math.pi*2)))
print("The i: "..i)
i = i + 5
end

I want the camera to basically go around the character when they join the game so that the character can see his character in a 3D vision. So they can make their own character.

Thank you for reading my question and I hope you guys can help me out!

~~ KingLoneCat

1 answer

Log in to vote
1
Answered by 8 years ago

This is the case where trigonometric math functions could help you out a lot.

-- RenderStepped fires every frame, thus very useful for visual effects and camera
local renderStep = game:GetService( "RunService" ).RenderStepped

local cam = workspace.CurrentCamera
local player = game.Players:GetPlayerFromCharacter(script.Parent)
local char = player.Character
local torso = char:WaitForChild("Torso")

-- The distance the camera should circle in
local r = 3
local speed = 2

-- For custom cameras I always prefer Scriptable camera, since it gives you full control over it
cam.CameraType = Enum.CameraType.Scriptable

-- Keep track of time instead
local t = 0
while true do
    -- They wait method on event allows you to yield(pause) the script til the next time the event is called
    -- RenderStepped returns the amount of time passed since last frame
    local delta = renderStep:wait()
    -- By adding together delta time, you can effectively keep track of time passed since the loop began
    t = t + delta

    -- Something similar to what you had, except makes use of the trigonometric function properties
    -- If you're interested in how exactly it works, you might want to learn on "Unit circle"
    cam.CFrame = cam.CFrame * CFrame.new( math.cos( t * speed )*r, 0, math.sin( t * speed )*r )
end
0
Well your script somewhat works... However your script makes my camera revolve in really big circles and I tried making r smaller however that decreases the speed of the camera's movement which I don't want I am trying to make a Custom Characterizer. So could you please edit your answer to make it something like that? Because I want it to be able to move fast however revolve in small circles. KingLoneCat 2642 — 8y
0
I added tweakable speed variable. And for camera distance you tweak the r. ZarsBranchkin 885 — 8y
Ad

Answer this question