Skip to content

Commit 858cd12

Browse files
committed
SameAsFollowObject renamed to SameAsFollowTarget. Also add special API to get LookAt/Follow pos/rot
1 parent d94af60 commit 858cd12

18 files changed

+171
-30
lines changed

Base/Editor/Editors/CinemachineHardLockToTargetEditor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public override void OnInspectorGUI()
1515
MessageType.Warning);
1616
EditorGUI.BeginChangeCheck();
1717
GUI.enabled = false;
18-
EditorGUILayout.LabelField(" ", "Hard Lock has no settings", EditorStyles.miniLabel);
18+
EditorGUILayout.LabelField(" ", "No additional settings", EditorStyles.miniLabel);
1919
GUI.enabled = true;
2020
DrawRemainingPropertiesInInspector();
2121
}

Base/Editor/Editors/CinemachineHardLookAtEditor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public override void OnInspectorGUI()
1515
MessageType.Warning);
1616
EditorGUI.BeginChangeCheck();
1717
GUI.enabled = false;
18-
EditorGUILayout.LabelField(" ", "Hard Look At has no settings", EditorStyles.miniLabel);
18+
EditorGUILayout.LabelField(" ", "No additional settings", EditorStyles.miniLabel);
1919
GUI.enabled = true;
2020
DrawRemainingPropertiesInInspector();
2121
}

Base/Editor/Editors/CinemachineHardLookAtEditor.cs.meta

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Base/Editor/Editors/CinemachineOrbitalTransposerEditor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static void DrawTransposerGizmos(CinemachineOrbitalTransposer target, GizmoType
7272
CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(target.VirtualCamera);
7373
if (brain != null)
7474
up = brain.DefaultWorldUp;
75-
Vector3 pos = target.FollowTarget.position;
75+
Vector3 pos = target.FollowTargetPosition;
7676

7777
Quaternion orient = target.GetReferenceOrientation(up);
7878
up = orient * Vector3.up;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace Cinemachine.Editor
5+
{
6+
[CustomEditor(typeof(CinemachineSameAsFollowTarget))]
7+
public sealed class CinemachineSameAsFollowTargetEditor : BaseEditor<CinemachineSameAsFollowTarget>
8+
{
9+
public override void OnInspectorGUI()
10+
{
11+
BeginInspector();
12+
if (Target.FollowTarget == null)
13+
EditorGUILayout.HelpBox(
14+
"Same As Follow Target requires a Follow target. It will set the virtual camera's rotation to be the same as that of the Follow Target.",
15+
MessageType.Warning);
16+
EditorGUI.BeginChangeCheck();
17+
GUI.enabled = false;
18+
EditorGUILayout.LabelField(" ", "No additional settings", EditorStyles.miniLabel);
19+
GUI.enabled = true;
20+
DrawRemainingPropertiesInInspector();
21+
}
22+
}
23+
}

Base/Editor/Editors/CinemachineSameAsFollowTargetEditor.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Base/Editor/Editors/CinemachineTransposerEditor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ static void DrawTransposerGizmos(CinemachineTransposer target, GizmoType selecti
6262
CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(target.VirtualCamera);
6363
if (brain != null)
6464
up = brain.DefaultWorldUp;
65-
Vector3 targetPos = target.FollowTarget.position;
65+
Vector3 targetPos = target.FollowTargetPosition;
6666
Vector3 desiredPos = target.GeTargetCameraPosition(up);
6767
Gizmos.DrawLine(targetPos, desiredPos);
68-
Gizmos.DrawWireSphere(desiredPos, HandleUtility.GetHandleSize(desiredPos) / 20);
68+
//Gizmos.DrawWireSphere(desiredPos, HandleUtility.GetHandleSize(desiredPos) / 20);
6969
Gizmos.color = originalGizmoColour;
7070
}
7171
}

Base/Runtime/Behaviours/CinemachineVirtualCamera.cs

+17-2
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,28 @@ void UpdateComponentPipeline()
403403
m_ComponentPipeline = list.ToArray();
404404
}
405405

406+
private Transform mCachedLookAtTarget;
407+
private CinemachineVirtualCameraBase mCachedLookAtTargetVcam;
406408
private CameraState CalculateNewState(Vector3 worldUp, float deltaTime)
407409
{
408410
// Initialize the camera state, in case the game object got moved in the editor
409411
CameraState state = PullStateFromVirtualCamera(worldUp);
410412

411-
if (LookAt != null)
412-
state.ReferenceLookAt = LookAt.position;
413+
Transform lookAtTarget = LookAt;
414+
if (lookAtTarget != mCachedLookAtTarget)
415+
{
416+
mCachedLookAtTarget = lookAtTarget;
417+
mCachedLookAtTargetVcam = null;
418+
if (lookAtTarget != null)
419+
mCachedLookAtTargetVcam = lookAtTarget.GetComponent<CinemachineVirtualCameraBase>();
420+
}
421+
if (lookAtTarget != null)
422+
{
423+
if (mCachedLookAtTargetVcam != null)
424+
state.ReferenceLookAt = mCachedLookAtTargetVcam.State.FinalPosition;
425+
else
426+
state.ReferenceLookAt = lookAtTarget.position;
427+
}
413428

414429
// Update the state by invoking the component pipeline
415430
CinemachineCore.Stage curStage = CinemachineCore.Stage.Body;

Base/Runtime/Components/CinemachineComposer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ protected virtual Vector3 GetLookAtPointAndSetTrackedPoint(Vector3 lookAt)
124124
{
125125
Vector3 pos = lookAt;
126126
if (LookAtTarget != null)
127-
pos += LookAtTarget.transform.rotation * m_TrackedObjectOffset;
127+
pos += LookAtTargetRotation * m_TrackedObjectOffset;
128128

129129
m_Predictor.Smoothing = m_LookaheadSmoothing;
130130
m_Predictor.AddPosition(pos);

Base/Runtime/Components/CinemachineFramingTransposer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public override void MutateCameraState(ref CameraState curState, float deltaTime
311311

312312
//UnityEngine.Profiling.Profiler.BeginSample("CinemachineFramingTransposer.MutateCameraState");
313313
Vector3 camPosWorld = m_PreviousCameraPosition;
314-
curState.ReferenceLookAt = FollowTarget.position;
314+
curState.ReferenceLookAt = FollowTargetPosition;
315315
m_Predictor.Smoothing = m_LookaheadSmoothing;
316316
m_Predictor.AddPosition(curState.ReferenceLookAt);
317317
TrackedPoint = (m_LookaheadTime > 0)

Base/Runtime/Components/CinemachineHardLockToTarget.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class CinemachineHardLockToTarget : CinemachineComponentBase
2626
public override void MutateCameraState(ref CameraState curState, float deltaTime)
2727
{
2828
if (IsValid)
29-
curState.RawPosition = FollowTarget.position;
29+
curState.RawPosition = FollowTargetPosition;
3030
}
3131
}
3232
}

Base/Runtime/Components/CinemachineOrbitalTransposer.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public override void MutateCameraState(ref CameraState curState, float deltaTime
312312

313313
if (IsValid)
314314
{
315-
mLastTargetPosition = FollowTarget.position;
315+
mLastTargetPosition = FollowTargetPosition;
316316

317317
// Calculate the heading
318318
if (m_BindingMode != BindingMode.SimpleFollowWithWorldUp)
@@ -385,13 +385,13 @@ private float GetTargetHeading(
385385
switch (m_Heading.m_HeadingDefinition)
386386
{
387387
case Heading.HeadingDefinition.PositionDelta:
388-
velocity = FollowTarget.position - mLastTargetPosition;
388+
velocity = FollowTargetPosition - mLastTargetPosition;
389389
break;
390390
case Heading.HeadingDefinition.Velocity:
391391
velocity = mTargetRigidBody.velocity;
392392
break;
393393
case Heading.HeadingDefinition.TargetForward:
394-
velocity = FollowTarget.forward;
394+
velocity = FollowTargetRotation * Vector3.forward;
395395
break;
396396
default:
397397
case Heading.HeadingDefinition.WorldForward:

Base/Runtime/Components/CinemachineSameAsFollowObject.cs renamed to Base/Runtime/Components/CinemachineSameAsFollowTarget.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ namespace Cinemachine
44
{
55
/// <summary>
66
/// This is a CinemachineComponent in the Aim section of the component pipeline.
7-
/// Its job is to aim the camera hard at the LookAt target.
7+
/// Its job is to match the orientation of the Follow target.
88
/// </summary>
99
[DocumentationSorting(DocumentationSortingAttribute.Level.UserRef)]
1010
[AddComponentMenu("")] // Don't display in add component menu
1111
[RequireComponent(typeof(CinemachinePipeline))]
1212
[SaveDuringPlay]
13-
public class CinemachineSameAsFollowObject : CinemachineComponentBase
13+
public class CinemachineSameAsFollowTarget : CinemachineComponentBase
1414
{
1515
/// <summary>True if component is enabled and has a Follow target defined</summary>
1616
public override bool IsValid { get { return enabled && FollowTarget != null; } }
@@ -19,14 +19,13 @@ public class CinemachineSameAsFollowObject : CinemachineComponentBase
1919
/// Always returns the Aim stage</summary>
2020
public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Aim; } }
2121

22-
/// <summary>Applies the composer rules and orients the camera accordingly</summary>
22+
/// <summary>Orients the camera to match the Follow target's orientation</summary>
2323
/// <param name="curState">The current camera state</param>
24-
/// <param name="deltaTime">Used for calculating damping. If less than
25-
/// zero, then target will snap to the center of the dead zone.</param>
24+
/// <param name="deltaTime">Not used.</param>
2625
public override void MutateCameraState(ref CameraState curState, float deltaTime)
2726
{
2827
if (IsValid)
29-
curState.RawOrientation = FollowTarget.transform.rotation;
28+
curState.RawOrientation = FollowTargetRotation;
3029
}
3130
}
3231
}

Base/Runtime/Components/CinemachineTrackedDolly.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public override void MutateCameraState(ref CameraState curState, float deltaTime
170170
prevPos = m_Path.GetPathPositionFromDistance(prevPos);
171171
// This works in path units
172172
m_PathPosition = m_Path.FindClosestPoint(
173-
FollowTarget.transform.position,
173+
FollowTargetPosition,
174174
Mathf.FloorToInt(prevPos),
175175
(deltaTime < 0 || m_AutoDolly.m_SearchRadius <= 0)
176176
? -1 : m_AutoDolly.m_SearchRadius,
@@ -278,11 +278,11 @@ private Quaternion GetTargetOrientationAtPathPoint(Quaternion pathOrientation, V
278278
return Quaternion.LookRotation(pathOrientation * Vector3.forward, up);
279279
case CameraUpMode.FollowTarget:
280280
if (FollowTarget != null)
281-
return FollowTarget.rotation;
281+
return FollowTargetRotation;
282282
break;
283283
case CameraUpMode.FollowTargetNoRoll:
284284
if (FollowTarget != null)
285-
return Quaternion.LookRotation(FollowTarget.rotation * Vector3.forward, up);
285+
return Quaternion.LookRotation(FollowTargetRotation * Vector3.forward, up);
286286
break;
287287
}
288288
return Quaternion.LookRotation(transform.rotation * Vector3.forward, up);

Base/Runtime/Components/CinemachineTransposer.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ protected void InitPrevFrameStateInfo(
164164
{
165165
m_previousTarget = FollowTarget;
166166
m_targetOrientationOnAssign
167-
= (m_previousTarget == null) ? Quaternion.identity : FollowTarget.rotation;
167+
= (m_previousTarget == null) ? Quaternion.identity : FollowTargetRotation;
168168
}
169169
if (deltaTime < 0)
170170
{
@@ -197,7 +197,7 @@ protected void TrackTarget(
197197
}
198198
m_PreviousReferenceOrientation = dampedOrientation;
199199

200-
Vector3 targetPosition = FollowTarget.position;
200+
Vector3 targetPosition = FollowTargetPosition;
201201
Vector3 currentPosition = m_PreviousTargetPosition;
202202
Vector3 worldOffset = targetPosition - currentPosition;
203203

@@ -262,7 +262,7 @@ public Vector3 GeTargetCameraPosition(Vector3 worldUp)
262262
{
263263
if (!IsValid)
264264
return Vector3.zero;
265-
return FollowTarget.position + GetReferenceOrientation(worldUp) * EffectiveOffset;
265+
return FollowTargetPosition + GetReferenceOrientation(worldUp) * EffectiveOffset;
266266
}
267267

268268
/// <summary>State information for damping</summary>
@@ -276,7 +276,7 @@ public Quaternion GetReferenceOrientation(Vector3 worldUp)
276276
{
277277
if (FollowTarget != null)
278278
{
279-
Quaternion targetOrientation = FollowTarget.rotation;
279+
Quaternion targetOrientation = FollowTargetRotation;
280280
switch (m_BindingMode)
281281
{
282282
case BindingMode.LockToTargetOnAssign:
@@ -289,7 +289,7 @@ public Quaternion GetReferenceOrientation(Vector3 worldUp)
289289
return targetOrientation;
290290
case BindingMode.SimpleFollowWithWorldUp:
291291
{
292-
Vector3 dir = FollowTarget.position - VcamState.RawPosition;
292+
Vector3 dir = FollowTargetPosition - VcamState.RawPosition;
293293
if (dir.AlmostZero())
294294
break;
295295
return Uppify(Quaternion.LookRotation(dir, worldUp), worldUp);

Base/Runtime/Core/CinemachineComponentBase.cs

+94
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,100 @@ public Transform LookAtTarget
4343
}
4444
}
4545

46+
private Transform mCachedFollowTarget;
47+
private CinemachineVirtualCameraBase mCachedFollowTargetVcam;
48+
49+
/// <summary>Get the position of the Follow target. Special handling: If the Follow target is
50+
/// a VirtualCamera, returns the vcam State's position, not the transform's position</summary>
51+
public Vector3 FollowTargetPosition
52+
{
53+
get
54+
{
55+
Transform target = FollowTarget;
56+
if (target != mCachedFollowTarget)
57+
{
58+
mCachedFollowTargetVcam = null;
59+
mCachedFollowTarget = target;
60+
if (target != null)
61+
mCachedFollowTargetVcam = target.GetComponent<CinemachineVirtualCameraBase>();
62+
}
63+
if (mCachedFollowTargetVcam != null)
64+
return mCachedFollowTargetVcam.State.FinalPosition;
65+
if (target != null)
66+
return target.position;
67+
return Vector3.zero;
68+
}
69+
}
70+
71+
/// <summary>Get the rotation of the Follow target. Special handling: If the Follow target is
72+
/// a VirtualCamera, returns the vcam State's rotation, not the transform's rotation</summary>
73+
public Quaternion FollowTargetRotation
74+
{
75+
get
76+
{
77+
Transform target = FollowTarget;
78+
if (target != mCachedFollowTarget)
79+
{
80+
mCachedFollowTargetVcam = null;
81+
mCachedFollowTarget = target;
82+
if (target != null)
83+
mCachedFollowTargetVcam = target.GetComponent<CinemachineVirtualCameraBase>();
84+
}
85+
if (mCachedFollowTargetVcam != null)
86+
return mCachedFollowTargetVcam.State.FinalOrientation;
87+
if (target != null)
88+
return target.rotation;
89+
return Quaternion.identity;
90+
}
91+
}
92+
93+
private Transform mCachedLookAtTarget;
94+
private CinemachineVirtualCameraBase mCachedLookAtTargetVcam;
95+
96+
/// <summary>Get the position of the LookAt target. Special handling: If the LookAt target is
97+
/// a VirtualCamera, returns the vcam State's position, not the transform's position</summary>
98+
public Vector3 LookAtTargetPosition
99+
{
100+
get
101+
{
102+
Transform target = LookAtTarget;
103+
if (target != mCachedLookAtTarget)
104+
{
105+
mCachedLookAtTargetVcam = null;
106+
mCachedLookAtTarget = target;
107+
if (target != null)
108+
mCachedLookAtTargetVcam = target.GetComponent<CinemachineVirtualCameraBase>();
109+
}
110+
if (mCachedLookAtTargetVcam != null)
111+
return mCachedLookAtTargetVcam.State.FinalPosition;
112+
if (target != null)
113+
return target.position;
114+
return Vector3.zero;
115+
}
116+
}
117+
118+
/// <summary>Get the rotation of the LookAt target. Special handling: If the LookAt target is
119+
/// a VirtualCamera, returns the vcam State's rotation, not the transform's rotation</summary>
120+
public Quaternion LookAtTargetRotation
121+
{
122+
get
123+
{
124+
Transform target = LookAtTarget;
125+
if (target != mCachedLookAtTarget)
126+
{
127+
mCachedLookAtTargetVcam = null;
128+
mCachedLookAtTarget = target;
129+
if (target != null)
130+
mCachedLookAtTargetVcam = target.GetComponent<CinemachineVirtualCameraBase>();
131+
}
132+
if (mCachedLookAtTargetVcam != null)
133+
return mCachedLookAtTargetVcam.State.FinalOrientation;
134+
if (target != null)
135+
return target.rotation;
136+
return Quaternion.identity;
137+
}
138+
}
139+
46140
/// <summary>Returns the owner vcam's CameraState.</summary>
47141
public CameraState VcamState
48142
{

Base/Runtime/Core/CinemachineCore.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed class CinemachineCore
1313
public static readonly int kStreamingVersion = 20170927;
1414

1515
/// <summary>Human-readable Cinemachine Version</summary>
16-
public static readonly string kVersionString = "2.1";
16+
public static readonly string kVersionString = "2.1.10";
1717

1818
/// <summary>
1919
/// Stages in the Cinemachine Component pipeline, used for

0 commit comments

Comments
 (0)