I’m making a third person game and I’m trying to keep the player on the left side of the screen even when the camera rotates.
as @highpockets write, you can attach camera as a child of the player, however if you need a animated, less rigid or “natural” following, I did a script about a month ago, is similar to a ton of scripts that are already on the net, so I dont think to is a great discovery:
public class SlowFollower : MonoBehaviour {
public Transform Target; //target to follow
public Vector3 PositionFollowing;//position of the camera relative to the target
Vector3 PosBuffer = Vector3.zero;
Quaternion RotBuffer = Quaternion.identity;
// if u are using physics to move the player, to evade camera jittering use LateUpdate but, if it dont work like with me, use FixedUpdate
void FixedUpdate () {
if (Target) {
//chek if target change position or rotation
if (!((PosBuffer- Target.position).sqrMagnitude < .001f)
&& Quaternion.Angle(RotBuffer, Target.rotation) < .05f) {
SlowFollowing();
PosBuffer = Target.position;
RotBuffer = transform.rotation;
}
}
}
void SlowFollowing(){
PosBuffer = Target.position + (transform.forward * PositionFollowing.y +
transform.right * PositionFollowing.x -
transform.up * PositionFollowing.z);
//u can change this to make a fast or slow following, to change position use lerp, this tweak just work if divide with 2
transform.position = (PosBuffer+transform.position)/2;
transform.rotation = Quaternion.Lerp (transform.rotation, Target.rotation, .2f);
}
}