generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Scripting a Camera relative to part

Previous Thread :: Next Thread 
radioactivated is not online. radioactivated
Joined: 05 Sep 2009
Total Posts: 1181
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
radioactivated is not online. radioactivated
Joined: 05 Sep 2009
Total Posts: 1181
07 Dec 2014 09:34 AM
bump
Report Abuse
radioactivated is not online. radioactivated
Joined: 05 Sep 2009
Total Posts: 1181
07 Dec 2014 10:26 AM
bump
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
07 Dec 2014 10:27 AM
You should use a Scriptable camera type.
Report Abuse
radioactivated is not online. radioactivated
Joined: 05 Sep 2009
Total Posts: 1181
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
radioactivated is not online. radioactivated
Joined: 05 Sep 2009
Total Posts: 1181
07 Dec 2014 11:12 AM
bump
Report Abuse
radioactivated is not online. radioactivated
Joined: 05 Sep 2009
Total Posts: 1181
07 Dec 2014 03:46 PM
bump
Report Abuse
radioactivated is not online. radioactivated
Joined: 05 Sep 2009
Total Posts: 1181
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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
07 Dec 2014 05:13 PM
When you learn how CFrames work, this will be really easy.
Report Abuse
radioactivated is not online. radioactivated
Joined: 05 Sep 2009
Total Posts: 1181
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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. 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
radioactivated is not online. radioactivated
Joined: 05 Sep 2009
Total Posts: 1181
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 is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image