- Home /
Combining 2 camera systems
Hi, I have these 2 camera mechanics I'd like to combine but can't figure out how to do it. Also to keep each mechanic working as intended, for example when I move the player that the camera will still rotate around the moving player.
The code here is each mechanic as clean as possible, so each on it's own work perfectly but when I enable both either one of them breaks or both depending on the attempt.
some extra info about each mechanic:
Mechanic 1: rotation around the player fueled by horizontal by the right analog stick.
Mechanic 2: Simple distance offsets of the camera's position towards the player's position
horizontal = Input.GetAxisRaw("Right Analog StickX");
//Mechanic 1 (rotate around player)
transform.RotateAround(player.transform.position, Vector3.up * horizontal, 1.0f);
//Mechanic 2 (distance offsets towards player position)
Vector3 camera_pos;
Vector3 curr_pos = transform.position;
Vector3 diff_pos = player_transform.position - curr_pos;
if (diff_pos.z < -4 + (2 * movement.cubic) || diff_pos.y < 3)
{
camera_pos = new Vector3(player.transform.position.x,
player.transform.position.y + distance_to_player_y,
player.transform.position.z + distance_to_player_z);
}
else
{
camera_pos = transform.position;
}
transform.position = Vector3.Lerp(transform.position, camera_pos, 5f);
Your answer
![](https://koobas.hobune.stream/wayback/20220612100911im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Smooth Attached Object movement 1 Answer
camera slides and bounces while moving C# 1 Answer
Global movement 0 Answers
How to make my player look in the direction of its movement? 3 Answers
RTS Camera Rotation and Movement 0 Answers