So the player constantly move on a diagonal direction, and the camera follow him (on x and y, it’s 2d gameplay)
But when the player jump, i want the camera continue to follow him but not following him on his jump movement. I don’t if it’s clear !
Is there a way to achieve that ?
Edit :
my first atempt was that, but cause the player is always moving, it’s not working perfectly
using UnityEngine;
using System.Collections;
public class cameraScript : MonoBehaviour
{
public Transform target;
public CharacterController controller;
private int offSetz = -100;
public float offSetx;
public float offSety;
private float lockPos;
void Start()
{
}
void Update()
{
if (controller.isGrounded)
{
transform.position = new Vector3(target.transform.position.x + offSetx, target.transform.position.y + offSety, offSetz);
lockPos = target.transform.position.y;
}
else {
transform.position = new Vector3(target.transform.position.x + offSetx, lockPos + offSety, offSetz);
}
}
}