Question by
phnestel · Jan 29, 2017 at 02:50 PM ·
unity 5camera followyaxis
Camerafollow with another target in the background (should only change the y-axis
I have two capsule objects in a split screen shooter. At this moment, the first camera follows player one, and has the target player two. The second camera follows player two, and has the target player one.
It feels a bit strange to play, because the game has different platforms with different height. How can I only follow the target along the y-axis?
The followed object shouldn't change at all. It should only look at the target. This is what I have, so far:
using UnityEngine;
using System.Collections;
public class CameraFollow : MonoBehaviour
{
[SerializeField]
private float distanceAway;
[SerializeField]
private float distanceUp;
[SerializeField]
private float smooth;
[SerializeField]
private Transform followedObject;
[SerializeField]
private Transform target;
private Vector3 toPosition;
void LateUpdate()
{
toPosition = followedObject.transform.position - target.transform.position;
GetComponent<Camera>().transform.position = followedObject.transform.position + toPosition.normalized *distanceAway;
transform.LookAt(followedObject);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612105857im_/https://answers.unity.com/themes/thub/images/avi.jpg)