mirror of
https://github.com/ConjureETS/VZ.git
synced 2026-03-25 10:51:14 +00:00
fix camera following the squad after transitioning
This commit is contained in:
parent
42f7739be9
commit
6239893ce1
1353
Assets/Scenes/jp-movements.unity
Normal file
1353
Assets/Scenes/jp-movements.unity
Normal file
File diff suppressed because it is too large
Load Diff
8
Assets/Scenes/jp-movements.unity.meta
Normal file
8
Assets/Scenes/jp-movements.unity.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5149561f6267e6347a3cd27e1736f7a8
|
||||||
|
timeCreated: 1439593876
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -18,8 +18,8 @@ public class PlayerController : MonoBehaviour {
|
|||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start () {
|
void Start () {
|
||||||
currentSquadIndex = 0;
|
currentSquadIndex = 0;
|
||||||
squadCamera.SetTarget(squads[currentSquadIndex].gameObject.transform.position);
|
//squadCamera.SetTarget(squads[currentSquadIndex].gameObject.transform.position);
|
||||||
|
squadCamera.SetTarget(squads[currentSquadIndex].gameObject.transform);
|
||||||
movementManager = GetComponent<MovementManager>();
|
movementManager = GetComponent<MovementManager>();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -30,15 +30,15 @@ public class PlayerController : MonoBehaviour {
|
|||||||
// switching between squads
|
// switching between squads
|
||||||
if (Input.GetButtonDown("Opt1-" + (int)player)) {
|
if (Input.GetButtonDown("Opt1-" + (int)player)) {
|
||||||
currentSquadIndex = 0;
|
currentSquadIndex = 0;
|
||||||
squadCamera.SetTarget(squads[0].gameObject.transform.position);
|
squadCamera.SetTarget(squads[0].transform);
|
||||||
}
|
}
|
||||||
if (Input.GetButtonDown("Opt2-" + (int)player)) {
|
if (Input.GetButtonDown("Opt2-" + (int)player)) {
|
||||||
currentSquadIndex = 1;
|
currentSquadIndex = 1;
|
||||||
squadCamera.SetTarget(squads[1].gameObject.transform.position);
|
squadCamera.SetTarget(squads[1].transform);
|
||||||
}
|
}
|
||||||
if (Input.GetButtonDown("Opt3-" + (int)player)) {
|
if (Input.GetButtonDown("Opt3-" + (int)player)) {
|
||||||
currentSquadIndex = 2;
|
currentSquadIndex = 2;
|
||||||
squadCamera.SetTarget(squads[2].gameObject.transform.position);
|
squadCamera.SetTarget(squads[2].transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
// movements
|
// movements
|
||||||
|
|||||||
@ -3,15 +3,15 @@ using System.Collections;
|
|||||||
|
|
||||||
public class SquadCamera : MonoBehaviour {
|
public class SquadCamera : MonoBehaviour {
|
||||||
|
|
||||||
private Vector3 target;
|
private Transform targetTransform;
|
||||||
public float y = 25f; // store the height value since it will never change
|
public float y = 25f; // store the height value since it will never change
|
||||||
public float offsetZ = -5f;
|
public float offsetZ = -5f;
|
||||||
|
|
||||||
public float transitionDuration = 2.5f;
|
public float transitionDuration = 2.5f;
|
||||||
|
private bool isTransitioning;
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start () {
|
void Start () {
|
||||||
target = Vector3.zero;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
@ -19,25 +19,34 @@ public class SquadCamera : MonoBehaviour {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTarget(Vector3 newTarget) {
|
void LateUpdate() {
|
||||||
Vector3 previousTarget = target;
|
// Early out if we don't have a target
|
||||||
|
if (!targetTransform) return;
|
||||||
|
|
||||||
if (!previousTarget.Equals(newTarget)) {
|
if (!isTransitioning) {
|
||||||
|
transform.position = new Vector3(targetTransform.position.x, y, targetTransform.position.z + offsetZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
target = newTarget;
|
|
||||||
|
public void SetTarget(Transform newTarget) {
|
||||||
|
Transform previousTarget = targetTransform;
|
||||||
|
|
||||||
|
if (!previousTarget || !previousTarget.Equals(newTarget)) {
|
||||||
|
|
||||||
|
targetTransform = newTarget;
|
||||||
StopCoroutine("Transition");
|
StopCoroutine("Transition");
|
||||||
StartCoroutine("Transition");
|
StartCoroutine("Transition");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IEnumerator Transition() {
|
IEnumerator Transition() {
|
||||||
|
|
||||||
float t = 0.0f;
|
float t = 0.0f;
|
||||||
Vector3 startingPos = transform.position;
|
Vector3 startingPos = transform.position;
|
||||||
Vector3 destination = new Vector3( target.x, y, target.z + offsetZ); // add the offset
|
Vector3 destination = new Vector3(targetTransform.position.x, y, targetTransform.position.z + offsetZ); // add the offset
|
||||||
|
|
||||||
|
isTransitioning = true;
|
||||||
while (t < 1.0f) {
|
while (t < 1.0f) {
|
||||||
|
|
||||||
t += Time.deltaTime * (Time.timeScale / transitionDuration);
|
t += Time.deltaTime * (Time.timeScale / transitionDuration);
|
||||||
@ -45,5 +54,6 @@ public class SquadCamera : MonoBehaviour {
|
|||||||
transform.position = Vector3.Lerp(startingPos, destination, t);
|
transform.position = Vector3.Lerp(startingPos, destination, t);
|
||||||
yield return 0;
|
yield return 0;
|
||||||
}
|
}
|
||||||
|
isTransitioning = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user