Hi!
I am trying to create a simple camera that would follow the player and only allow orbital movement sideways around the player. I have two pieces of code. Both work flawlessly on their own.
One for orbiting around the player:
void FixedUpdate()
{
Transform PC = GameObject.FindWithTag("Player").transform;
float p88re = Input.GetAxis("Kylgsuund"); // identify button press
float kiiruskonstant = 2f; //fix orbiting speed
transform.RotateAround(PC.position, Vector3.up, kiiruskonstant * p88re); //turn camera
}
And the other for following the player:
{
public Transform target; // The position that that camera will be following.
public float smoothing = 5f; // The speed with which the camera will be following.
Vector3 offset; // The initial offset from the target.
void Start ()
{
// Calculate the initial offset.
offset = transform.position - target.position;
}
void FixedUpdate ()
{
// Create a postion the camera is aiming for based on the offset from the target.
Vector3 targetCamPos = target.position + offset;
// Smoothly interpolate between the camera's current position and it's target position.
transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
}
}
Which ever way I try to combine the two, the camera goes bananas, losing focus on the player and original rotation axis as soon as I move the character and try to rotate the camera. I just want the camera to follow the player, keeping the original distance and angle and moving around the player when axis movement is applied.
I’ve been stuck with this for two days now. Any and all pointers appreciated.