Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

fix: billboard now looks to the camera even in 3rd person mode #1474

Merged
merged 5 commits into from
Oct 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DCL.Components;
using DCL.Components;
using System.Collections;
using UnityEngine;

Expand All @@ -22,8 +22,8 @@ public class Model

public override IEnumerator ApplyChanges(string newJson)
{
DCLCharacterController.OnCharacterMoved -= OnCharacterMoved;
DCLCharacterController.OnCharacterMoved += OnCharacterMoved;
cameraPosition.OnChange -= CameraPositionChanged;
cameraPosition.OnChange += CameraPositionChanged;

model = SceneController.i.SafeFromJson<Model>(newJson);

Expand All @@ -45,7 +45,7 @@ public override IEnumerator ApplyChanges(string newJson)

public void OnDestroy()
{
DCLCharacterController.OnCharacterMoved -= OnCharacterMoved;
cameraPosition.OnChange -= CameraPositionChanged;
}

// This runs on LateUpdate() instead of Update() to be applied AFTER the transform was moved by the transform component
Expand Down Expand Up @@ -82,17 +82,19 @@ Vector3 GetLookAtVector()
return lookAtDir.normalized;
}

void OnCharacterMoved(DCLCharacterPosition position)
void ChangeOrientation()
{
ChangeOrientation();
if (entityTransform == null)
return;

Vector3 lookAtVector = GetLookAtVector();
if(lookAtVector != Vector3.zero)
entityTransform.forward = lookAtVector;
}

void ChangeOrientation()
private void CameraPositionChanged(Vector3 current, Vector3 previous)
{
if (entityTransform != null)
{
entityTransform.forward = GetLookAtVector();
}
ChangeOrientation();
}
}
}