So I’m trying to make a scuffed camera bobbing script, and I’m getting very close, a lot closer than I was.
All I’m trying to do right now is found out why the heck CFrame.Angles() won’t allow me to add CFrame:ToEulerAnglesXYZ. So far what I have is some script someone gave me a long time ago so make a part do a loop, and make it look at a part.
This could all be over if roblox would just simply add a CFrame.Orientation, but instead it is a hassle, almost impossible to get rotation out of a cframe.
Edit: one thing that could fix this is camera.cframe += …, but ofc i cant do +=.
watch the last 10 seconds of the second video. you can see me getting mad at it
its the exact same as cframe, cframe.rotation is useless since it is just the entire cframe
lol i didn’t know that, my bad. I tried to add the camera cframe.rotation with blue.cframe.rotation, but roblox doesnt like that. (cant attach video,error)
Im pretty sure ToEulerAngles returns a tuple of 3 numbers, and adding those tuples together only returns the first values of each added together for some reason
The CFrame.Position just returns the position part of the CFrame, which is already a vector (just drops all the rotation parts). The CFrame.Rotation returns a whole CFrame with the translation part basically zeroed out.
You could translate the CFrame of a temp part by using the method I posted above and then pull the Part.Orientation from that part, or the CFrame:ToOrientation() gives pretty similar results; although it gives the angle measurements in radians instead of degrees. Can fix that with something like:
-- results similar to Part.Orientation
local x,y,z = workspace.Part.CFrame:ToOrientation()
x = math.deg(x)
y = math.deg(y)
z = math.deg(z)
Sorry had to leave for a bit.
So, what is the rotation needed for? Do you want that as part of the bob, or are you trying to rotate the cam to follow the player or what?
You aiming for this kind of thing? Trying to figure out what effect you are going for.
local camera = workspace.Camera
local RunService = game:GetService("RunService")
local count = 0
RunService.RenderStepped:Connect(function(dx)
local translate = Vector3.new(math.sin(5*count)/4 - 0.5, math.sin(2*count)/2 - 0.5, 0)
local cf = camera.CFrame:ToWorldSpace(CFrame.new(translate))
camera.CFrame = cf
count += dx
end)
or this? (if you want the horizon to lift/fall and rly make players seasick)
local camera = workspace.Camera
local RunService = game:GetService("RunService")
local count = 0
RunService.RenderStepped:Connect(function(dx)
local translate = Vector3.new(math.sin(5*count)/4 - 0.5, math.sin(2*count)/2 - 0.5, 0)
local cf = camera.CFrame:ToWorldSpace(CFrame.new(translate))
local rotate = CFrame.fromAxisAngle(cf:ToObjectSpace(camera.CFrame).RightVector, math.sin(count)/1000)
camera.CFrame = cf * rotate
count += dx
end)
sorry for the confusion, yes, I am trying to create some bob type effect. Heres the full code:
infinite loop code:
local runservice = game:GetService('RunService')
local part = workspace.blue
local x = part.Position.X
local y = part.Position.Y
local z = part.Position.Z
local speed = 5 -- feel free to change
local strength = 1 -- feel free to change
runservice.Heartbeat:Connect(function()
local currentTime = tick() -- current time is the elapsed
part.Position = Vector3.new(x + math.sin(currentTime*speed)*strength, y + math.sin(2*currentTime*speed)*strength/3, z)
part.CFrame = CFrame.lookAt(part.Position,workspace.pink.Position)
end)
Cam Code:
local blue = workspace.blue
local player = game.Players.LocalPlayer
local char = player.Character
local camera = workspace.CurrentCamera
local runService = game:GetService("RunService")
local cframe1 = blue.CFrame
runService.RenderStepped:Connect(function()
local x,y,z = blue.CFrame:ToOrientation()
--x = math.rad(x)
--y = math.rad(y)
--z = math.rad(z)
local x1,y1,z1 = camera.CFrame:ToOrientation()
--x1 = math.rad(x1)
--y1 = math.rad(y1)
--z1 = math.rad(z1)
local x2,y2,z2 = x+x1,y+y1,z+z1
camera.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(x*2,y*2,z*2) * camera.CFrame.Rotation
end)
Edit: The cam code is something I threw together trying to understand things and isnt mine