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
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Always in front of Camera

Previous Thread :: Next Thread 
glosgreen2 is not online. glosgreen2
Joined: 06 Jul 2009
Total Posts: 1303
10 Apr 2014 08:23 AM
How do I make sure that a Part is always in front of the Camera using CFrames?
Report Abuse
masterCameron101 is not online. masterCameron101
Joined: 28 Mar 2010
Total Posts: 1377
10 Apr 2014 08:25 AM
Do you want the camera to follow it?
Report Abuse
glosgreen2 is not online. glosgreen2
Joined: 06 Jul 2009
Total Posts: 1303
10 Apr 2014 08:27 AM
No, I would like it to just be placed in front of the Camera.
Here's what I've tried:

Part.CFrame = Camera.CoordinateFrame*CFrame.new(5,0,5)

But, of course, that will only work if the Camera is facing in a positive direction. If it faces a negative direction, it will become out of view as it will be situated behind the Camera.
Report Abuse
glosgreen2 is not online. glosgreen2
Joined: 06 Jul 2009
Total Posts: 1303
10 Apr 2014 08:51 AM
For example, if my Camera's position is {-15,0,-15} and I want my part at {0,0,0}, I can just say Camera.CoordinateFrame+Vector3.new(15,0,15), but if I want to do it the other way around, I'd have to change it to -Vector3.new().

But what would I do if the Camera's position was {-15,0,15} or {15,0,-15}?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Apr 2014 09:30 AM
You want it to be 15, 0, -15 studs in front of the camera? (15 studs right and 15 studs forward) Just do: part.CFrame = camera.CoordinateFrame * CFrame.new(15, 0, -15)
Report Abuse
glosgreen2 is not online. glosgreen2
Joined: 06 Jul 2009
Total Posts: 1303
10 Apr 2014 01:12 PM
Okay, let me try and explain this better...

I want a Part to always stay in front of my Camera, no matter where I turn it. I can do as you suggested, but that doesn't always assure that it's placed in front of my Camera at all times. If I turn to a certain direction, it'll go behind the Camera, which is not what I want.
Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
10 Apr 2014 01:59 PM
maybe you can find the difference between the camera's cframe and the cameras subject and then calculate the position of the part in relation to the difference.

example (not code - make your own :D)
#

camera cframe = (20,20,20)
camera subject cframe = (15,15,15)
difference = (5,5,5)
part cframe = camera cframe - (1,1,1) or (2,2,2) / up to difference

going past the difference would put the part behind subject and going inverted on the difference would put the part behind the camera (or vise-versa [logics])
Report Abuse
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
10 Apr 2014 03:23 PM
part.CFrame = camera.CoordinateFrame * CFrame.new(0,0,-15) * CFrame.new(15,0,0)

or,

part.CFrame = camera.CoordinateFrame:toWorldSpace(15,0,-15)

Dunno, try that. What cnt posted should be working fine, really.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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