- Home /
Specific camera coordinates based on players coordinates.
So i want to make my camera always be y (y coordinate) units over my player and xz (x and z coordinates) units offset from players y axis, while still having this piece of script work:
if (Input.GetAxisRaw("Mouse ScrollWheel") > 0) { transform.LookAt(target.transform.position); transform.RotateAround(target.transform.position, Vector3.up, 20 * Time.deltaTime * 10f); // A = 1; } if (Input.GetAxisRaw("Mouse ScrollWheel") < 0) { transform.LookAt(target.transform.position); transform.RotateAround(target.transform.position, Vector3.down, 20 * Time.deltaTime * 10f); //A = -1; }
can someone help me?! I can already lock the y coordinate, but getting x and z to work is impossible for me.I also can't just make the camera child to the player as the player is a rolling ball, and the camera totally freaks out when it starts to roll. I hope i explained what i want to do enough and if not just ask and I'll try to clarify it a bit more.
Answer by Shaolin-Dave · Jan 03, 2019 at 11:11 PM
The way I usually have the camera follow the player is by creating an empty GameObject that does only one thing: follows the player. It's not a child of the player, it just constantly updates it's transform to match the player's position (or move towards the player's position at a certain speed for camera smoothing). Make your camera a child of this empty GameObject, and it will maintain it's position/rotation in relation to the player until you tell it to do otherwise.
The "otherwise" is where you lost me. You shared some code but didn't explain at all what you're end goal is, nor is the code commented. It seems you want the camera's position to stay offset from the players, but for it's rotation to point at a different target? The method I described should not affect this.
That's exaclly what i wanted! I tried to do i purely with code, and I didnt think tomake a "middleman" between two objects. $$anonymous$$aybe I just don't have a proper $$anonymous$$dset for now. Thank you very very much!
Your answer
![](https://koobas.hobune.stream/wayback/20220612185030im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
FPS cam for Roll -a-Ball like game 1 Answer
Camera leaning problems (Lerping) 0 Answers
Cinemachine & Playmaker 3rd person zoom 0 Answers
Slight camera stutter with Cinemachine 2D (Video inside) 1 Answer
Automatic 3rd person camera 1 Answer