Boopbot
|
  |
| Joined: 11 Jul 2008 |
| Total Posts: 2284 |
|
|
| 04 Mar 2015 12:21 AM |
For some reason Roblox won't let you rotate the camera around the Z-axis. I even took their camera rotation script:
local target = workspace.Part local camera = workspace.CurrentCamera camera.CameraType = Enum.CameraType.Scriptable camera.CameraSubject = target local angle = 0 while wait() do camera.CoordinateFrame = CFrame.new(target.Position) --Start at the position of the part * CFrame.Angles(0, angle, 0) --Rotate by the angle * CFrame.new(0, 0, 5) --Move the camera backwards 5 units angle = angle + math.rad(1) end
But this can only rotate the camera along the X-axis and Y-axis. Putting an angle in the Z component doesn't do anything.
Is there a way around this? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 04 Mar 2015 12:25 AM |
| http://wiki.roblox.com/index.php?title=API:Class/Camera/SetRoll |
|
|
| Report Abuse |
|
|
Boopbot
|
  |
| Joined: 11 Jul 2008 |
| Total Posts: 2284 |
|
|
| 04 Mar 2015 12:26 AM |
No, not the axis relative to the player, the axis in 3D space.
Like the XYZ orthogonal vectors. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 04 Mar 2015 12:28 AM |
| Use the same method, except SetRoll after setting to CFrame.new(blah.Position) so the CFrame has "no" rotation. |
|
|
| Report Abuse |
|
|
Boopbot
|
  |
| Joined: 11 Jul 2008 |
| Total Posts: 2284 |
|
|
| 04 Mar 2015 12:44 AM |
| Well, no matter what it always tilts the camera, instead of raising/lowering it. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 04 Mar 2015 12:50 AM |
You want to "raise/lower" the camera? Not rotate it? Just add Vector3.new(0, disp, 0) to raise it using the global axes and * CFrame.new(0, disp, 0) to raise it using its local axes (so if the top face is facing down, it would actually go down) |
|
|
| Report Abuse |
|
|
Boopbot
|
  |
| Joined: 11 Jul 2008 |
| Total Posts: 2284 |
|
|
| 04 Mar 2015 12:51 AM |
| No, raise/lower as in around the Z-axis, like the camera is on a pole perpendicular to the z-axis and rotates. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 04 Mar 2015 12:52 AM |
| SetRoll does a rotation about the camera's local Z axis. This requires some kind of rotation relative to the global z axis unless your camera is looking parallel or anti parallel with the y axis (meaning that the local z axis is equivalent to the global y axis). |
|
|
| Report Abuse |
|
|
Boopbot
|
  |
| Joined: 11 Jul 2008 |
| Total Posts: 2284 |
|
|
| 04 Mar 2015 12:54 AM |
| Exactly. I want to rotate the camera about the global Z-axis. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 04 Mar 2015 01:01 AM |
Ok, about the global z it is...
local target = workspace.Part local camera = workspace.CurrentCamera camera.CameraType = Enum.CameraType.Scriptable camera.CameraSubject = target local angle = 0 while wait() do camera.CoordinateFrame = CFrame.Angles(0, 0, angle)*CFrame.new(target.Position) angle = angle + math.pi/4 -- lets use a less harsh angle. end |
|
|
| Report Abuse |
|
|
Boopbot
|
  |
| Joined: 11 Jul 2008 |
| Total Posts: 2284 |
|
|
| 04 Mar 2015 01:07 AM |
| Almost works, but for some reason it zooms the camera all the way out. |
|
|
| Report Abuse |
|
|
Tacobus
|
  |
| Joined: 14 Sep 2012 |
| Total Posts: 6 |
|
|
| 04 Mar 2015 01:10 AM |
| What exactly are you trying to do with the camera? Make a 360-degree panorama, a top-down shooter, or what? It's hard to help without a little bit of insight into your project, because the proper method for doing these things can vary based on what you want done, and what else your script has to interact with. |
|
|
| Report Abuse |
|
|
Boopbot
|
  |
| Joined: 11 Jul 2008 |
| Total Posts: 2284 |
|
|
| 04 Mar 2015 01:11 AM |
| I'm trying to make a 3rd person camera script, so the camera rotates as you move the mouse. So far the only problem is that the camera cannot rotate along the global Z-axis. I've got it down so I can rotate it along the X-axis and Y-axis using the mouse. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 04 Mar 2015 01:14 AM |
I'm assuming you mean my code zoomed it all the way in?
Just add back the *CFrame.new(0,0,5) if that is the case. |
|
|
| Report Abuse |
|
|
Boopbot
|
  |
| Joined: 11 Jul 2008 |
| Total Posts: 2284 |
|
|
| 04 Mar 2015 01:17 AM |
| Nope, adding the * CFrame.new(0, 0, 5) back in doesn't change anything. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 04 Mar 2015 01:20 AM |
| Is there a place where I can test out the camera you have as of now? |
|
|
| Report Abuse |
|
|
Boopbot
|
  |
| Joined: 11 Jul 2008 |
| Total Posts: 2284 |
|
|
| 04 Mar 2015 01:26 AM |
Here's the original, with just the X and Y-axes working: --Inside a localscript, in the PlayerGui
local Input = game:GetService("UserInputService") local camera = workspace.CurrentCamera local player = game.Players.LocalPlayer local character = player.Character local angleorigx = 0 local angleorigy = 0 local AngleSup = 0.01
camera.CoordinateFrame = CFrame.new(character.Head.Position) Input.MouseBehavior = Enum.MouseBehavior.LockCenter Input.InputChanged:connect(function(InputObject) if InputObject.UserInputType == Enum.UserInputType.MouseMovement then camera.CoordinateFrame = CFrame.new(character.Head.Position) * CFrame.fromEulerAnglesXYZ( math.cos(angleorigx)*( angleorigy + AngleSup*InputObject.Delta.y), -(angleorigx + AngleSup*InputObject.Delta.x), 0) * CFrame.new(0, 0, 5) --Move the camera backwards 5 units
angleorigx = angleorigx + AngleSup*InputObject.Delta.x angleorigy = angleorigy + AngleSup*InputObject.Delta.y
end end)
And
And here it is with some "fixes"
local Input = game:GetService("UserInputService") local camera = workspace.CurrentCamera local player = game.Players.LocalPlayer local character = player.Character local angleorigx = 0 local angleorigy = 0 local AngleSup = 0.01
camera.CoordinateFrame = CFrame.new(character.Head.Position) Input.MouseBehavior = Enum.MouseBehavior.LockCenter Input.InputChanged:connect(function(InputObject) if InputObject.UserInputType == Enum.UserInputType.MouseMovement then camera.CoordinateFrame = CFrame.fromEulerAnglesXYZ( math.cos(angleorigx)*( angleorigy + AngleSup*InputObject.Delta.y), -(angleorigx + AngleSup*InputObject.Delta.x), math.sin(angleorigx)*( angleorigy + AngleSup*InputObject.Delta.y)) * CFrame.new(character.Head.Position)* CFrame.new(0, 0, 5) --Move the camera backwards 5 units
angleorigx = angleorigx + AngleSup*InputObject.Delta.x angleorigy = angleorigy + AngleSup*InputObject.Delta.y
end end)
Still zooming out randomly, but it does rotate along the Z-axis |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 04 Mar 2015 01:39 AM |
| Ok, real quick, how is is supposed to act differently from the default camera? |
|
|
| Report Abuse |
|
|
Tacobus
|
  |
| Joined: 14 Sep 2012 |
| Total Posts: 6 |
|
|
| 04 Mar 2015 01:44 AM |
| It's free-look versus click-and-drag. I imagine if you added a key to toggle it, and worked all the bugs out, it could be quite useful. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 04 Mar 2015 02:00 AM |
local Input = game:GetService("UserInputService") local camera = workspace.CurrentCamera local player = game:GetService("Players").LocalPlayer local mouse = player:GetMouse() local character = player.Character or player.CharacterAdded:Wait() local head = character:WaitForChild("Head") local angleorigx = 0 local angleorigy = 0 local Sensitivity = 500 local FocalLength = 10
camera.CoordinateFrame = CFrame.new(character.Head.Position) Input.MouseBehavior = Enum.MouseBehavior.LockCenter Input.InputChanged:connect(function(InputObject) if InputObject.UserInputType == Enum.UserInputType.MouseMovement then angleorigy = (angleorigy + math.rad(-InputObject.Delta.x/mouse.ViewSizeX*Sensitivity))%(2*math.pi) --// the modulus just keeps the math clean by keeping the range from 0 to 2pi angleorigx = angleorigx + math.rad(-InputObject.Delta.y/mouse.ViewSizeY*Sensitivity) print(-InputObject.Delta.y/mouse.ViewSizeY) if angleorigx > math.pi/2 then angleorigx = math.pi/2 elseif angleorigx < -math.pi/2 then angleorigx = -math.pi/2 end
end end) game:GetService("RunService").RenderStepped:connect(function() camera.CameraType = Enum.CameraType.Scriptable camera.CoordinateFrame = CFrame.new(head.Position)* CFrame.fromEulerAnglesXYZ(0,angleorigy,0)* CFrame.fromEulerAnglesXYZ(angleorigx,0,0) *CFrame.new(0,0,FocalLength) end)
That took a while...
OK. Your problems. You where applying the rotations about the x and y axes at the same time,normal camera's require that you rotate by y first and then by x. Second, you where doing an angular change relative to pixels rather than how far across the screen the mouse moved (issue of high vs low pixel density screens assuming mouse speed is comparable for players). Third, you where updating only when the mouse moved. I could walk away and the camera wouldn't follow. Fourth, use the scriptable property of camera for things like this. |
|
|
| Report Abuse |
|
|
Boopbot
|
  |
| Joined: 11 Jul 2008 |
| Total Posts: 2284 |
|
|
| 04 Mar 2015 09:29 AM |
| Thank you guys so much. I really don't know anything about Roblox's camera functions. |
|
|
| Report Abuse |
|
|
LucasLua
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 7386 |
|
|
| 04 Mar 2015 09:37 AM |
| One thing I don't like about the Scriptable CameraType is that Camera.Focus property is broken. For all the other CameraTypes setting the Focus behaves like it should but it doesn't work for Scriptable, so we change the facing direction of the CoordinateFrame so the camera still behaves like it would with Focus set. |
|
|
| Report Abuse |
|
|
Boopbot
|
  |
| Joined: 11 Jul 2008 |
| Total Posts: 2284 |
|
|
| 04 Mar 2015 09:43 AM |
| Also I added a Raytrace function to the script so the camera can't go through walls. |
|
|
| Report Abuse |
|
|
Boopbot
|
  |
| Joined: 11 Jul 2008 |
| Total Posts: 2284 |
|
|
| 05 Mar 2015 09:35 AM |
Ok, weird problem. Apparently if you ever unlock the mouse, say for using a menu, when you re-lock the mouse the camera controls are completely off. It's either jagged and laggy when moving or it turns in the complete opposite direction that the mouse moves.
And disabling/re-enabling the script doesn't do anything, the camera is still acting up. |
|
|
| Report Abuse |
|
|
|
| 05 Mar 2015 10:50 AM |
| But LucasLua, I don't really see a need to use the Focus property... I just set the CoordinateFrame as it is so much easier IMO |
|
|
| Report Abuse |
|
|