Skip to content

Commit

Permalink
Fix incorrect positioning of cameras that dont follow replay offset i…
Browse files Browse the repository at this point in the history
…n new replays
  • Loading branch information
kinsi55 committed Jun 26, 2021
1 parent ee51c3f commit cd6b73c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions Middlewares/Smoothfollow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public bool pivotingOffset {
}
}

[JsonIgnore] internal bool isAttachedToFP = true;
[JsonIgnore] internal bool useLocalPosition = true;
[JsonIgnore] internal Transform parent;


Expand Down Expand Up @@ -57,15 +57,16 @@ class Smoothfollow : CamMiddleware, IMHandler {
}

Transform parentToUse = null;

bool isAttachedToReplayCam = false;
if(
ScoresaberUtil.isInReplay &&
//UnityEngine.XR.XRDevice.isPresent &&
settings.type == Configuration.CameraType.FirstPerson
) {
if(settings.Smoothfollow.followReplayPosition) {
parentToUse = ScoresaberUtil.replayCamera?.transform;
settings.Smoothfollow.isAttachedToFP = true;
settings.Smoothfollow.useLocalPosition = true;
isAttachedToReplayCam = true;
}

if(parent == ScoresaberUtil.replayCamera?.transform)
Expand All @@ -74,7 +75,7 @@ class Smoothfollow : CamMiddleware, IMHandler {

if(parentToUse == null && settings.type == Configuration.CameraType.FirstPerson && HookFPFC.isInFPFC && HookFPFC.cameraInstance != null) {
parentToUse = HookFPFC.cameraInstance?.transform;
settings.Smoothfollow.isAttachedToFP = false;
settings.Smoothfollow.useLocalPosition = false;
}

if(parentToUse == null)
Expand All @@ -83,10 +84,10 @@ class Smoothfollow : CamMiddleware, IMHandler {
if(parentToUse == null || parentToUse.gameObject?.activeInHierarchy != true) {
if(settings.type == Configuration.CameraType.FirstPerson) {
parent = parentToUse = Camera.main?.transform;
settings.Smoothfollow.isAttachedToFP = true;
settings.Smoothfollow.useLocalPosition = true;
} else if(settings.type == Configuration.CameraType.Attached) {
parent = parentToUse = GameObject.Find(settings.Smoothfollow.targetParent)?.transform;
settings.Smoothfollow.isAttachedToFP = false;
settings.Smoothfollow.useLocalPosition = false;
}
}

Expand All @@ -99,13 +100,13 @@ class Smoothfollow : CamMiddleware, IMHandler {
var targetPosition = parentToUse.position;
var targetRotation = parentToUse.rotation;

if(settings.Smoothfollow.isAttachedToFP) {
if(settings.Smoothfollow.useLocalPosition) {
targetPosition = parentToUse.localPosition;
targetRotation = parentToUse.localRotation;

if(HookRoomAdjust.position != Vector3.zero || HookRoomAdjust.rotation != Quaternion.identity) {
// Not exactly sure why we gotta exclude replays from this, but thats what it is
if(settings.type == Configuration.CameraType.FirstPerson && !ScoresaberUtil.isInReplay) {
if(settings.type == Configuration.CameraType.FirstPerson && !isAttachedToReplayCam) {
targetPosition = (HookRoomAdjust.rotation * targetPosition) + HookRoomAdjust.position;
targetRotation = HookRoomAdjust.rotation * targetRotation;
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "Camera2",
"name": "Camera2",
"author": "Kinsi55",
"version": "0.4.2",
"version": "0.4.3",
"description": "If Camera Plus is so good, why is there no Camera Plus 2?",
"gameVersion": "1.16.1",
"dependsOn": {
Expand Down

0 comments on commit cd6b73c

Please sign in to comment.