- Home /
How to keep the player on the left side o the screen?
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.
If your camera is a child of your player object and is meant to be turning when your player turns, just translate the camera in localSpace to the distance you want to keep the player off center.
Answer by DCordoba · Jan 22, 2019 at 12:30 AM
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);
}
}
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Rotating Camera around player object 0 Answers
Camera bounce back? 0 Answers
Rotating following camera for a sphere 1 Answer
I need some help with camera rotations 0 Answers