Question by
Ptolemy2002 · Aug 22, 2019 at 03:32 PM ·
cameratransformpositionoffset
Change the offset whenever the position changes
In my game, I have the following two scripts:
void LateUpdate()
{
transform.position = target.position + offset;
if (rotating) {
if (!reverse)
{
transform.RotateAround(target.position, Vector3.up, rotateSpeed * Time.deltaTime * -1);
}
else {
transform.RotateAround(target.position, Vector3.up, rotateSpeed * Time.deltaTime);
}
offset = transform.position - target.position;
}
}
and
void Update()
{
float scroll = Input.GetAxis("Mouse ScrollWheel");
if (scroll > 0)
{
transform.position += transform.forward * zoomAmount * 10;
}
else if (scroll < 0) {
transform.position -= transform.forward * zoomAmount * 10;
}}
The first one is made to allow the camera to rotate around a specific target with user input. The second one is made to allow the camera to zoom in or out based on the scrollwheel.
My problem is that whenever the scrollwheel script changes the position, the rotation script resets it with the offset variable. I need to make it so that whenever the position of the camera changes, the offset variable also changes. However, the script still needs to switch it's position based on the position of the player.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612211031im_/https://answers.unity.com/themes/thub/images/avi.jpg)