I found a nice working camera script but it doesn’t look ahead when the player is moving forward. I want it so that when I’m moving to the right it is like one or 2 units ahead so I can see where I’m going better. When I’m moving left I want it to do the same in the other direction. How would I achieve this? Here is the camera script:
public GameObject cameraTarget; // object to look at or follow
public GameObject player; // player object for moving
public float smoothTime = 0.1f; // time for dampen
public bool cameraFollowX = true; // camera follows on horizontal
public bool cameraFollowY = true; // camera follows on vertical
public bool cameraFollowHeight = true; // camera follow CameraTarget object height
public float cameraHeight = 2.5f; // height of camera adjustable
public Vector2 velocity; // speed of camera movement
private Transform thisTransform; // camera Transform
// Use this for initialization
void Start()
{
thisTransform = transform;
}
// Update is called once per frame
void FixedUpdate()
{
if (cameraFollowX)
{
thisTransform.position = new Vector3(Mathf.SmoothDamp(thisTransform.position.x, cameraTarget.transform.position.x, ref velocity.x, smoothTime), thisTransform.position.y, thisTransform.position.z);
}
if (cameraFollowY)
{
// to do
}
if (!cameraFollowX & cameraFollowHeight)
{
// to do
}
}