/
Camera.yaml
1319 lines (1184 loc) · 46.7 KB
/
Camera.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: Camera
type: class
category: Gameplay
memory_category: Instances
summary: |
A class which defines a view of the 3D world.
description: |
The **Camera** object defines a view of the 3D world. In a running experience,
each client has its own **Camera** object which resides in that client's local
`Class.Workspace`, accessible through the `Class.Workspace.CurrentCamera`
property.
The most important camera properties are:
- `Class.Camera.CFrame` which represents the position and orientation of the
camera.
- `Class.Camera.CameraType` which is read by the experience's camera scripts
and determines how the camera should update each frame.
- `Class.Camera.CameraSubject` which is read by the experience's camera
scripts and determines what object the camera should follow.
- `Class.Camera.FieldOfView` which represents the visible extent of the
observable world.
- `Class.Camera.Focus` which represents the point the camera is looking at.
It's important this property is set, as certain visuals will be more
detailed and will update more frequently depending on how close they are to
the focus point.
See [Customizing the Camera](../../../workspace/camera.md) for more
information on how to adjust and customize the camera's behavior.
code_samples:
inherits:
- Instance
tags:
- NotReplicated
deprecation_message: ''
properties:
- name: Camera.CFrame
summary: |
The `Datatype.CFrame` of the `Class.Camera`, defining its position and
orientation in the 3D world.
description: |
This property is the `Datatype.CFrame` of the `Class.Camera`, defining its
position and orientation in the 3D world. Note that some transformations,
such as the rotation of the head when using VR devices, are not reflected
in this property, so you should use
`Class.Camera:GetRenderCFrame()|GetRenderCFrame()` to obtain the "true"
`Datatype.CFrame` of the camera.
You can move the camera by setting this property. However, the default
camera scripts also set it, so you should either:
- Set the camera `Class.Camera.CameraType` to `Enum.CameraType.Scriptable`
so that the default camera scripts will not update the camera's
`Datatype.CFrame`. This method is simplest and recommended in most
cases.
- Completely replace the default camera scripts with alternatives. This
approach is only recommended if you do not need any default camera
functionality.
The most intuitive way to position and orient the `Class.Camera` is by
using the `Datatype.CFrame.lookAt()` constructor. In the following
example, the `Class.Camera` is positioned at
`Datatype.Vector3.new(0, 10, 0)` and is oriented to be looking towards
`Datatype.Vector3.new(10, 0, 0)`.
```lua
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local pos = Vector3.new(0, 10, 0)
local lookAtPos = Vector3.new(10, 0, 0)
workspace.CurrentCamera.CFrame = CFrame.lookAt(pos, lookAtPos)
```
Although the camera can be placed in the manner demonstrated above, you
may want to animate it to move smoothly from one `Datatype.CFrame` to
another. For this, you can either:
- Set the camera's position/orientation every frame with
`Class.RunService:BindToRenderStep()` and the `Datatype.CFrame:Lerp()`
method.
- Create and play a `Class.Tween` that animates the position/orientation
of the camera:
```lua
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local player = Players.LocalPlayer
local character = player.Character
if not character or character.Parent == nil then
character = player.CharacterAdded:Wait()
end
local pos = camera.CFrame * Vector3.new(0, 20, 0)
local lookAtPos = character.PrimaryPart.Position
local targetCFrame = CFrame.lookAt(pos, lookAtPos)
local tween = TweenService:Create(camera, TweenInfo.new(2), {CFrame = targetCFrame})
tween:Play()
```
code_samples:
type: CFrame
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: true
- name: Camera.CameraSubject
summary: |
The `Class.Humanoid` or `Class.BasePart` that is the `Class.Camera`
subject.
description: |
**CameraSubject** accepts a variety of `Class.Instance|Instances`. The
default camera scripts respond differently to the available settings:
- By default, the camera scripts follow the local character's
`Class.Humanoid`, factoring in the humanoid's current state and
`Class.Humanoid.CameraOffset`.
- When set to a `Class.BasePart`, the camera scripts follow its position,
with a vertical offset in the case of `Class.VehicleSeat|VehicleSeats`.
**CameraSubject** cannot be set to `nil`. Attempting to do so will revert
it to its previous value.
To restore **CameraSubject** to its default value, set it to the local
character's `Class.Humanoid`:
```lua
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local function resetCameraSubject()
if workspace.CurrentCamera and localPlayer.Character then
local humanoid = localPlayer.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
workspace.CurrentCamera.CameraSubject = humanoid
end
end
end
```
code_samples:
type: Instance
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Camera
serialization:
can_load: true
can_save: true
- name: Camera.CameraType
summary: |
Specifies the `Enum.CameraType` to be read by the camera scripts.
description: |
The default Roblox camera scripts have several built-in behaviors. Setting
this property toggles between the various `Enum.CameraType` behaviors.
Note that some camera types require a valid `Class.Camera.CameraSubject`
to work correctly.
The default camera scripts will not move or update the camera if
**CameraType** is set to `Enum.CameraType.Scriptable`. For more
information on positioning and orienting the camera manually, see
`Class.Camera.CFrame`.
For all **CameraType** settings **except** `Enum.CameraType.Scriptable`,
the `Class.Camera.CameraSubject|CameraSubject` property represents the
object whose position the camera's `Class.Camera.Focus` is set to.
code_samples:
type: CameraType
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Camera
serialization:
can_load: true
can_save: true
- name: Camera.CoordinateFrame
summary: ''
description: |
The old version of the `Class.Camera.CFrame` property which functions
identically to it.
This item should be used in a `Class.LocalScript` in order to work as
expected online.
code_samples:
type: CFrame
tags:
- Hidden
- NotReplicated
- Deprecated
deprecation_message: |
This item has been superseded by `Class.Camera.CFrame` which should be
used in all new work.
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: false
- name: Camera.DiagonalFieldOfView
summary: |
Sets the angle of the camera's diagonal field of view.
description: |
Sets how many degrees in the diagonal direction (from one corner of the
viewport to its opposite corner) the camera can view. See
`Class.Camera.FieldOfView|FieldOfView` for a more general explanation of
field of view.
code_samples:
type: float
tags:
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Camera
serialization:
can_load: false
can_save: false
- name: Camera.FieldOfView
summary: |
Sets the angle of the camera's vertical field of view.
description: |
The **FieldOfView** property sets how many degrees in the vertical
direction the camera can view. This property is clamped between 1 and 120
degrees and defaults at 70. Very low or very high fields of view are not
recommended as they can be disorientating to players.
Note that uniform scaling is enforced, meaning the vertical and horizontal
field of view are always related by the aspect ratio of the screen.
Suggested uses for **FieldOfView** (FOV) include:
- Reducing FOV to give the impression of magnification, for example when
using binoculars.
- Increasing FOV when the player is "sprinting" to give the impression of
a lack of control.
code_samples:
type: float
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Camera
serialization:
can_load: true
can_save: true
- name: Camera.FieldOfViewMode
summary: |
Determines the FOV value of the `Class.Camera` that's invariant under
viewport size changes.
description: |
The camera's field of view (FOV) must be updated to reflect
`Class.Camera.ViewportSize|ViewportSize` changes. The value of
**FieldOfViewMode** determines which FOV value will be kept constant.
For example, when this property is set to `Enum.FieldOfViewMode.Vertical`,
the horizontal FOV is updated when the viewport is resized, but the
vertical FOV is kept constant. If this property is set to
`Enum.FieldOfViewMode.Diagonal`, both horizontal and vertical FOV might be
changed to keep the diagonal FOV constant.
code_samples:
type: FieldOfViewMode
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Camera
serialization:
can_load: true
can_save: true
- name: Camera.Focus
summary: |
Sets the area in 3D space that is prioritized by Roblox's graphical
systems.
description: |
Certain graphical operations the engine performs, such as updating
lighting, can take time or computational effort to complete. The camera's
**Focus** property tells the engine which area in 3D space to prioritize
when performing such operations. For example, dynamic lighting from
objects such as `Class.PointLight|PointLights` may not render at distances
far from the focus.
The default Roblox camera scripts automatically set **Focus** to follow
the `Class.Camera.CameraSubject` (usually a `Class.Humanoid`). However,
**Focus** will **not** automatically update when
`Class.Camera.CameraType|CameraType` is set to
`Enum.CameraType.Scriptable` or when the default camera scripts are not
being used. In these cases, you should update **Focus** every frame, using
`Class.RunService:BindToRenderStep()` function at the
`Enum.RenderPriority.Camera` priority.
**Focus** has no bearing on the position or orientation of the camera; see
`Class.Camera.CFrame` for this.
code_samples:
type: CFrame
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: true
- name: Camera.HeadLocked
summary: |
Toggles whether the camera will automatically track the head motion of a
player using a VR device.
description: |
Toggles whether the camera will automatically track the head motion of a
player using a VR device. When `true` (default), the engine combines
`Class.Camera.CFrame` with the `Enum.UserCFrame` of the user's head to
render the player's view with head tracking factored in. The view will be
rendered at the following `Datatype.CFrame`:
```lua
local UserInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local headCFrame = UserInputService:GetUserCFrame(Enum.UserCFrame.Head)
headCFrame = headCFrame.Rotation + headCFrame.Position * camera.HeadScale
-- This will be equivalent to Camera:GetRenderCFrame()
local renderCFrame = camera.CFrame * headCFrame
```
It is recommended to **not** disable this property for the following
reasons:
- Players may experience motion sickness if an equivalent head tracking
solution is not added.
- The Roblox engine performs latency optimizations when **HeadLocked** is
true.
#### See Also
- `Class.VRService:GetUserCFrame()` which can be used to obtain the
`Datatype.CFrame` of the head.
- `Class.VRService:RecenterUserHeadCFrame()` which is used to recenter the
head to the current position and orientation of the VR device.
- The `Class.Camera:GetRenderCFrame()` function which returns the
`Class.Camera.CFrame` combined with the `Datatype.CFrame` of the user's
head.
code_samples:
type: bool
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: true
- name: Camera.HeadScale
summary: |
Sets the scale of the user's perspective of the world when using VR.
description: |
**HeadScale** is the scale of the user's perspective of the world when
using VR.
The size of 1 stud in VR is `0.3 meters / HeadScale`, meaning that larger
**HeadScale** values equate to the world looking smaller from the user's
perspective when using VR devices. For example, a part that's 1 stud tall
appears to be 0.6 meters tall to a VR player with a **HeadScale** of 0.5.
This property is automatically controlled by
`Class.VRService.AutomaticScaling` to align the player's perspective with
the size of their avatar. If you intend to control **HeadScale** yourself
or use custom characters, toggle `Class.VRService.AutomaticScaling` to
`Enum.VRScaling.Off`.
This property should not be confused with `Class.Humanoid.HeadScale` which
is a `Class.NumberValue` parented to a `Class.Humanoid` to control its
scaling.
code_samples:
type: float
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: true
- name: Camera.MaxAxisFieldOfView
summary: |
Sets the angle of the camera's field of view along the longest viewport
axis.
description: |
The **MaxAxisFieldOfView** property sets how many degrees along the
longest viewport axis the camera can view.
When the longest axis is the vertical axis, this property will behave
similar to the `Class.Camera.FieldOfView|FieldOfView` property. This is
generally the case when a device is in a portrait orientation. In a
landscape orientation, the longest axis will be the horizontal axis; in
this case, the property describes the horizontal field of view of the
`Class.Camera`.
code_samples:
type: float
tags:
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Camera
serialization:
can_load: false
can_save: false
- name: Camera.NearPlaneZ
summary: |
Describes the negative **Z** offset, in studs, of the camera's near
clipping plane.
description: |
The **NearPlaneZ** property describes how far away the camera's near
clipping plane is, in studs. The near clipping plane is a geometric plane
that sits in front of the camera's `Class.Camera.CFrame`. Anything between
this plane and the camera will not render, creating a cutaway view when
viewing objects at very short distances. The value of **NearPlaneZ**
varies across different platforms and is currently always between -0.1 and
-0.5.
<img src="/assets/engine-api/classes/Camera/NearPlaneZ.jpg" width="720" alt="Diagram showing how the NearPlaneZ clips (does not render) 3D content between the plane and the camera." />
code_samples:
type: float
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: true
- name: Camera.VRTiltAndRollEnabled
summary: |
Toggles whether to apply tilt and roll from the `Class.Camera.CFrame`
property while the player is using a VR device.
description: |
This property toggles whether to apply tilt and roll from the
`Class.Camera.CFrame` property while the player is using a VR device.
To prevent motion sickness, the horizon should remain level. Tilting and
rolling the player's view while using a VR device can cause a disconnect
between the player's physical space and the virtual space they are
viewing. Changing the apparent downwards direction can cause players to
lose balance or experience dizziness.
For these reasons, it is generally advisable to leave this property
disabled, unless you have extensively tested your experience for these
effects. Even with tilt and roll enabled, you may want to ensure the
player always has a stable reference frame, such as the interior of a
vehicle or a floor that can help the player ground themselves in their
physical space.
code_samples: []
type: bool
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: true
- name: Camera.ViewportSize
summary: |
Describes the dimensions, in pixels, of the client's viewport.
description: |
**ViewportSize** describes the dimensions, in pixels, of the client's
viewport.
This property ignores the GUI inset applied by the top bar, meaning the
center of the screen can be found at precisely at 50% of the viewport in
both directions. You can find the position of a `Datatype.Vector3` in the
world on the viewport using `Class.Camera:WorldToViewportPoint()`.
code_samples:
type: Vector2
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: true
- name: Camera.focus
summary: ''
description: ''
code_samples:
type: CFrame
tags:
- NotReplicated
- Deprecated
deprecation_message: |
This property is a deprecated variant of `Class.Camera.Focus` which should
be used instead.
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: false
methods:
- name: Camera:GetLargestCutoffDistance
summary: |
Returns how much the `Class.Camera` needs to be pushed towards its
`Class.Camera.Focus|Focus` in order to make sure there is no obstructions
between the `Class.Camera.Focus` and `Class.Camera.CFrame`.
description: |
This function is used by _'PopperCam'_ in the default camera scripts to
ensure obstructions do not come between the `Class.Camera` and its
subject.
This function will check all `Class.BasePart|BaseParts` and
`Class.Terrain` in the `Class.Workspace` with the following exceptions:
- Any `Class.Instance` specified in the _ignoreList_ (including its
descendants) will be ignored
- `Class.BasePart|BaseParts` with `Class.BasePart.CanCollide` set to false
are ignored
- `Class.BasePart|BaseParts` with a `Class.BasePart.Transparency` greater
than 0.95 will be ignored Water `Class.Terrain` is ignored
Note, as this function requires an _ignoreList_ to run, you should pass an
empty table when none is required.
code_samples:
parameters:
- name: ignoreList
type: Objects
default:
summary: |
An array of `Class.Instance|Instances` to ignore. Descendants of these
instances will also be ignored.
returns:
- type: float
summary: |
The distance, in studs, that the `Class.Camera` needs to be pushed
towards its `Class.Camera.Focus` to ensure there are no obstructions
between the `Class.Camera.Focus` and `Class.Camera.CFrame` of the
`Class.Camera`.
tags:
- Deprecated
deprecation_message: ''
security: None
thread_safety: Unsafe
- name: Camera:GetPanSpeed
summary: |
Returns the current 'pan' speed of the `Class.Camera`.
description: |
This function is broken and should not be used This function returns the
current 'pan' speed of the `Class.Camera`.
The 'pan' speed of the `Class.Camera` describes the speed at which the
`Class.Camera` is rotating around its `Class.Camera.Focus` around the Y
axis.
See also:
- `Class.Camera:GetTiltSpeed()` for the speed at which the `Class.Camera`
is rotating around its `Class.Camera.Focus` on the camera's X axis
- `Class.Camera:PanUnits()` to 'pan' the camera
- `Class.Camera:TiltUnits()` to 'tilt' the camera
code_samples:
parameters: []
returns:
- type: float
summary: |
The speed at which the `Class.Camera` is rotating around its
`Class.Camera.Focus` on the Y axis.
tags:
- Deprecated
deprecation_message: |
This function has been deprecated and no longer works. It should not be
used in new work.
security: None
thread_safety: Unsafe
- name: Camera:GetPartsObscuringTarget
summary: |
Returns an array of `Class.BasePart|BaseParts` that are obscuring the
lines of sight between the camera's `Class.Camera.CFrame` and the cast
points.
description: |
This method returns an array of `Class.BasePart|BaseParts` that are
obscuring the lines of sight between the camera's `Class.Camera.CFrame`
and `Datatype.Vector3` positions in the `castPoints` array. Any
`Class.Instance|Instances` included in the `ignoreList` array will be
ignored, along with their descendants.
The `castPoints` parameter is given as an array of `Datatype.Vector3`
positions. Note that the array of `Class.BasePart|BaseParts` returned is
in an arbitrary order, and no additional raycast data is provided. If you
need data such as hit position, hit material, or surface normal, you
should opt for the `Class.WorldRoot:Raycast()` method.
```lua
local camera = workspace.CurrentCamera
local castPoints = {
Vector3.new(0, 10, 0),
Vector3.new(0, 15, 0)
}
local ignoreList = {}
local partsObscuringTarget = camera:GetPartsObscuringTarget(castPoints, ignoreList)
```
If `Class.Terrain` obscures a cast point, `Class.BasePart|BaseParts`
obscuring the cast point between the obscuring `Class.Terrain` and the
cast point will not be returned.
code_samples:
- x-ray-function
parameters:
- name: castPoints
type: Array
default:
summary: |
An array of `Datatype.Vector3` positions of cast points.
- name: ignoreList
type: Objects
default:
summary: |
An array of `Class.Instance|Instances` that should be ignored, along
with their descendants.
returns:
- type: Objects
summary: |
An array of `Class.BasePart|BaseParts` that obscure the lines of sight
between the camera's `Class.Camera.CFrame` and the `castPoints`.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
- name: Camera:GetRenderCFrame
summary: |
Returns the actual `Datatype.CFrame`where the `Class.Camera` is being
rendered, accounting for any roll applied and the impact of VR devices.
description: |
This function returns the actual `Datatype.CFrame` of the `Class.Camera`
as it is rendered, including the impact of VR (VR head transformations are
not applied to the `Class.Camera.CFrame` property, so it is best practice
to use `Class.Camera:GetRenderCFrame()` to obtain the "true"
`Datatype.CFrame` of a player's view).
For example, when using VR, the `Class.Camera` is actually rendered at the
following `Datatype.CFrame`:
```lua
local UserInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local headCFrame = UserInputService:GetUserCFrame(Enum.UserCFrame.Head)
headCFrame = headCFrame.Rotation + headCFrame.Position * camera.HeadScale
renderCFrame = camera.CFrame * headCFrame
```
The camera's render `Datatype.CFrame` will only be changed to account for
the head when the `Class.Camera.HeadLocked` property is true.
code_samples:
parameters: []
returns:
- type: CFrame
summary: |
The `Datatype.CFrame` the `Class.Camera` is being rendered at.
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
- name: Camera:GetRoll
summary: |
Returns in radians the current roll, or rotation around the camera's
Z-axis, applied to the `Class.Camera` using `Class.Camera:SetRoll()`.
description: |
This function returns, in radians, the current roll applied to the
`Class.Camera` using `Class.Camera:SetRoll()`. Roll is defined as rotation
around the camera's Z-axis.
This function only returns roll applied using the `Class.Camera:SetRoll()`
function. Roll manually applied to the camera's `Class.Camera.CFrame` is
not accounted for. To obtain the actual roll of the `Class.Camera`,
including roll manually applied, you can use the following snippet:
```lua
local function getActualRoll()
local camera = workspace.CurrentCamera
local trueUp = Vector3.new(0, 1, 0)
local cameraUp = camera:GetRenderCFrame().upVector
return math.acos(trueUp:Dot(cameraUp))
end
```
code_samples:
- Camera-GetRoll1
parameters: []
returns:
- type: float
summary: |
The current roll applied by `Class.Camera:SetRoll()`, in radians.
tags: []
deprecation_message: |
This function has been deprecated. See below for a code snippet
demonstrating how to calculate the roll of the `Class.Camera`.
security: None
thread_safety: Unsafe
- name: Camera:GetTiltSpeed
summary: |
Returns the current 'tilt' speed of the `Class.Camera`.
description: |
This function is broken and should not be used.
This function returns the current 'tilt' speed of the `Class.Camera`.
The 'tilt' speed of the `Class.Camera` describes the speed at which the
`Class.Camera` is rotating around its `Class.Camera.Focus` around the
camera's X axis.
See also:
`Class.Camera:GetPanSpeed()` for the speed the `Class.Camera` is rotating
around the `Class.Camera.Focus` around the Y axis
`Class.Camera:PanUnits()` to 'pan' the camera `Class.Camera:TiltUnits()`
to 'tilt' the camera
code_samples:
parameters: []
returns:
- type: float
summary: |
The speed at which the `Class.Camera` is rotating around its
`Class.Camera.Focus` around the camera's X axis.
tags:
- Deprecated
deprecation_message: |
This function has been deprecated and no longer works. It should not be
used in new work.
security: None
thread_safety: Unsafe
- name: Camera:Interpolate
summary: |
Tweens the `Class.Camera` in a linear fashion towards a new
`Class.Camera.CFrame` and `Class.Camera.Focus` over a given duration.
description: |
This function tweens the `Class.Camera` in a linear fashion towards a new
`Class.Camera.CFrame` and `Class.Camera.Focus` over a given duration, for
example:
```lua
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(
CFrame.new(0, 10, 100),
CFrame.new(0, 0, 100),
5
)
```
Throughout the tween, the camera's `Class.Camera.CFrame` will be
orientated towards the camera's `Class.Camera.Focus`.
When the tween has completed, the camera's
`Class.Camera.InterpolationFinished` event will fire.
If this function is called while the `Class.Camera` is already tweening
the older tween will be stopped (without firing
`Class.Camera.InterpolationFinished`) and overridden by the new tween.
Interpolate can only be used if the current `Class.Camera.CameraType` is
_'Scriptable'_, regardless of whether the default camera scripts are being
used. If it is used with any other `Class.Camera.CameraType` an error will
be thrown.
You are advised to use `Class.TweenService` to tween the `Class.Camera`
instead as it is more reliable and offers a variety of easing styles. See
below for an example:
```lua
local TweenService = game:GetService("TweenService")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local tween = TweenService:Create(
camera,
TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{
CFrame = CFrame.new(0, 10, 100),
Focus = CFrame.new(0, 0, 100)
}
)
tween:Play()
```
code_samples:
parameters:
- name: endPos
type: CFrame
default:
summary: |
The `Datatype.CFrame` for the `Class.Camera` to tween to.
- name: endFocus
type: CFrame
default:
summary: |
The `Datatype.CFrame` for the camera's `Class.Camera.Focus` to tween
to.
- name: duration
type: float
default:
summary: |
The duration, in seconds, of the tween.
returns:
- type: void
summary: ''
tags:
- Deprecated
deprecation_message: |
This function has been deprecated. Instead use `Class.TweenService` to
smoothly animate the `Class.Camera`, see the code snippets below for an
example.
security: None
thread_safety: Unsafe
- name: Camera:PanUnits
summary: |
Pans the `Class.Camera` around the `Class.Camera.Focus` in 45 degree
increments around the Y axis.
description: |
This function pans the `Class.Camera` around the `Class.Camera.Focus` in
45 degree increments around the Y axis.
The rotation is applied to the camera's `Class.Camera.CFrame` property.
This function pans the `Class.Camera` in 45 degree increments, for
example:
```lua
workspace.CurrentCamera:PanUnits(1) -- 45 degrees
workspace.CurrentCamera:PanUnits(-2) -- -90 degrees
```
PanUnits does not require the `Class.Camera.CameraType` to be
_'Scriptable'_.
code_samples:
parameters:
- name: units
type: int
default:
summary: |
The number of 45 degree increments by which to pan the `Class.Camera`.
returns:
- type: void
summary: ''
tags:
- Deprecated
deprecation_message: |
This function was used for legacy camera controls and has since been
deprecated. Do not use in new work.
security: None
thread_safety: Unsafe
- name: Camera:ScreenPointToRay
summary: |
Creates a unit `Datatype.Ray` from a position on the screen (in pixels),
at a set depth from the `Class.Camera` orientated in the camera's
direction. Accounts for the GUI inset.
description: |
This function creates a unit `Datatype.Ray` from a 2D position on the
screen (defined in pixels), accounting for the GUI inset. The
`Datatype.Ray` originates from the `Datatype.Vector3` equivalent of the 2D
position in the world at the given depth (in studs) away from the
`Class.Camera`.
As this function acknowledges the GUI inset, the offset applied to GUI
elements (such as from the top bar) is accounted for. This means the
screen position specified will start in the top left corner below the top
bar. For an otherwise identical function that does not account for the GUI
offset, use `Class.Camera:ViewportPointToRay()`.
As the `Datatype.Ray` created is a unit ray, it is only one stud long. To
create a longer ray, you can do the following:
```lua
local camera = workspace.CurrentCamera
local length = 500
local unitRay = camera:ScreenPointToRay(100, 100)
local extendedRay = Ray.new(unitRay.Origin, unitRay.Direction * length)
```
code_samples:
parameters:
- name: x
type: float
default:
summary: |
The position on the X axis, in pixels, of the screen point at which to
originate the `Datatype.Ray`. This position accounts for the GUI
inset.
- name: 'y'
type: float
default:
summary: |
The position on the Y axis, in pixels, of the screen point at which to
originate the `Datatype.Ray`. This position accounts for the GUI
inset.
- name: depth
type: float
default: 0
summary: |
The depth from the `Class.Camera`, in studs, from which to offset the
origin of the `Datatype.Ray`.
returns:
- type: Ray
summary: |
A unit `Datatype.Ray`, originating from the equivalent
`Datatype.Vector3` world position of the given screen coordinates at
the given depth away from the `Class.Camera`. This ray is orientated
in the direction of the `Class.Camera`.
tags: []
deprecation_message: ''
security: None
thread_safety: Safe
- name: Camera:SetCameraPanMode
summary: |
Sets the `Enum.CameraPanMode` to be used by the `Class.Camera` on mobile
devices.
description: |
This function sets the `Enum.CameraPanMode` to be used by the
`Class.Camera` on mobile devices.
When the \*'EdgeBump' `Enum.CameraPanMode` is used, swipe to pan is
disabled and the edge bump camera controls are enabled.
SetCameraPan mode has no effect on Windows or Mac users.
code_samples:
parameters:
- name: mode
type: CameraPanMode
default: Classic
summary: |
The `Enum.CameraPanMode` to set the `Class.Camera` to.
returns:
- type: void
summary: ''
tags:
- Deprecated
deprecation_message: |
This function has been deprecated and should not be used in new work.
security: None
thread_safety: Unsafe
- name: Camera:SetRoll
summary: |
Sets the current rotation applied around the camera's Z-axis.