mirror of
https://github.com/ConjureETS/VZ.git
synced 2026-03-24 02:11:15 +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
|
||||
void Start () {
|
||||
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>();
|
||||
|
||||
}
|
||||
@ -30,15 +30,15 @@ public class PlayerController : MonoBehaviour {
|
||||
// switching between squads
|
||||
if (Input.GetButtonDown("Opt1-" + (int)player)) {
|
||||
currentSquadIndex = 0;
|
||||
squadCamera.SetTarget(squads[0].gameObject.transform.position);
|
||||
squadCamera.SetTarget(squads[0].transform);
|
||||
}
|
||||
if (Input.GetButtonDown("Opt2-" + (int)player)) {
|
||||
currentSquadIndex = 1;
|
||||
squadCamera.SetTarget(squads[1].gameObject.transform.position);
|
||||
squadCamera.SetTarget(squads[1].transform);
|
||||
}
|
||||
if (Input.GetButtonDown("Opt3-" + (int)player)) {
|
||||
currentSquadIndex = 2;
|
||||
squadCamera.SetTarget(squads[2].gameObject.transform.position);
|
||||
squadCamera.SetTarget(squads[2].transform);
|
||||
}
|
||||
|
||||
// movements
|
||||
|
||||
@ -3,15 +3,15 @@ using System.Collections;
|
||||
|
||||
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 offsetZ = -5f;
|
||||
|
||||
public float transitionDuration = 2.5f;
|
||||
private bool isTransitioning;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
target = Vector3.zero;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@ -19,25 +19,34 @@ public class SquadCamera : MonoBehaviour {
|
||||
|
||||
}
|
||||
|
||||
public void SetTarget(Vector3 newTarget) {
|
||||
Vector3 previousTarget = target;
|
||||
|
||||
if (!previousTarget.Equals(newTarget)) {
|
||||
|
||||
target = newTarget;
|
||||
void LateUpdate() {
|
||||
// Early out if we don't have a target
|
||||
if (!targetTransform) return;
|
||||
|
||||
if (!isTransitioning) {
|
||||
transform.position = new Vector3(targetTransform.position.x, y, targetTransform.position.z + offsetZ);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetTarget(Transform newTarget) {
|
||||
Transform previousTarget = targetTransform;
|
||||
|
||||
if (!previousTarget || !previousTarget.Equals(newTarget)) {
|
||||
|
||||
targetTransform = newTarget;
|
||||
StopCoroutine("Transition");
|
||||
StartCoroutine("Transition");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
IEnumerator Transition() {
|
||||
|
||||
float t = 0.0f;
|
||||
Vector3 startingPos = transform.position;
|
||||
Vector3 destination = new Vector3( target.x, y, target.z + offsetZ); // add the offset
|
||||
Vector3 startingPos = transform.position;
|
||||
Vector3 destination = new Vector3(targetTransform.position.x, y, targetTransform.position.z + offsetZ); // add the offset
|
||||
|
||||
isTransitioning = true;
|
||||
while (t < 1.0f) {
|
||||
|
||||
t += Time.deltaTime * (Time.timeScale / transitionDuration);
|
||||
@ -45,5 +54,6 @@ public class SquadCamera : MonoBehaviour {
|
||||
transform.position = Vector3.Lerp(startingPos, destination, t);
|
||||
yield return 0;
|
||||
}
|
||||
isTransitioning = false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user