|
| 07 Dec 2014 09:13 AM |
I'm making a system which lets players move and spin around in any axis, and I'm trying to make the camera move with the player's torso (as in, it always passes through the Torso's CFrame at the same angle from the same position). However, my code is failing to do this;
cam = workspace.CurrentCamera plr = game.Players.LocalPlayer char = plr.Character
torso = char:WaitForChild("Torso")
cam.CameraType = Enum.CameraType.Attach
while true do wait() cam.CoordinateFrame = CFrame.new(torso.CFrame.p - Vector3.new(0,-2,-15), torso.CFrame.lookVector) end
This code causes the camera to lock into the same position, but it seems that it only guarantees that the camera looks through the Torso's CFrame, and not necessarily keeping the angle the same. How can I guarantee that the angle by which the Camera looks through the part is always the same? |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 07 Dec 2014 10:27 AM |
| You should use a Scriptable camera type. |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2014 10:32 AM |
I've set the camera type to Scriptable, and the camera does not work as intended.
I suppose that I should further clarify, the camera should work as if looking at the player's back all the time, no matter what orientation the player is in. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 07 Dec 2014 05:10 PM |
| I did a bit of tinkering and found it might have to do with using object space instead of world space. But, how exactly does that work? (I did a cframe to object space by Vector3.new(1,1,1) and it still fails to "follow" as expected.) |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2014 05:13 PM |
| When you learn how CFrames work, this will be really easy. |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2014 05:23 PM |
What I was thinking was that the Camera should be placed 10 blocks behind the Torso's CFrame, while looking at its 3d position
The looking at part I got with the LookVector, but that other part is where I'm stuck. Could you explain very briefly? |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2014 05:29 PM |
Torso.CFrame * CFrame.Angles(0, -math.pi, 0) * CFrame.new(0, 0, 10)
That might need tweaking. |
|
|
| Report Abuse |
|
|
suremark
|
  |
| Joined: 13 Nov 2007 |
| Total Posts: 6315 |
|
|
| 07 Dec 2014 05:31 PM |
| I think it'd work properly without the angle offset. The Z axis points backwards in ROBLOX's coordinate system. |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2014 06:03 PM |
So I assume that that script works by taking the existing CFrame, rotating it about the y axis by -pi, and then offsetting it on the z axis by 10?
(side note, it works well with some tweaks. Thank you.) |
|
|
| Report Abuse |
|
|
suremark
|
  |
| Joined: 13 Nov 2007 |
| Total Posts: 6315 |
|
|
| 07 Dec 2014 06:10 PM |
Indeed. Multiplying two CFrames is equivalent to
CF1:toWorldSpace(CF2)
which takes the second CFrame and "puts it" in CF1's frame (hence the moniker 'CFrame' for Coordinate Frame). |
|
|
| Report Abuse |
|
|
|
| 07 Dec 2014 06:12 PM |
| Right, suremark, I just think that if you didn't rotate it, the camera would point backwards. I've done this on my "testing" place, but that was a month ago. |
|
|
| Report Abuse |
|
|
suremark
|
  |
| Joined: 13 Nov 2007 |
| Total Posts: 6315 |
|
|
| 07 Dec 2014 06:40 PM |
| Hmm. An offset of (0, 20, 20) seems to work right on my end. I suppose if it works for OP, then you're right though :P |
|
|
| Report Abuse |
|
|