Hi, i hope thi doesnt get deleted again, because i really cant find any answer on this site.
What I want is my camera to move to a different position (posiiton of the minimap in the images) when I press “V” and move it back when I press it again. The transition to the “minimap” position works perfectly but the it stays there no matter how many times i press the key. The original (initial in my code) position is overwritten by CURRENT position and I simply dont know how its possible…
Here is the code, i really dont know what could be wrong there:
void Start()
{
initialPosition = transform;
Debug.Log("Initial posiiton: " + initialPosition.position);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.V))
{
isViewChanged = true;
ChangePosition();
}
}
private void LateUpdate()
{
newPosition = transform.position;
newRotation = transform.rotation;
newPosition = Vector3.Lerp(transform.position, moveToPosition.position, 2f * Time.deltaTime);
newRotation = Quaternion.Lerp(transform.rotation, moveToPosition.rotation, 2f * Time.deltaTime);
transform.position = newPosition;
transform.rotation = newRotation;
}
void ChangePosition()
{
if (cameraPositionInMain)
{
moveToPosition = cam2;
cameraPositionInMain = false;
isViewChanged = true;
Debug.Log("Initial posiiton after first change: " + initialPosition.position);
}
else
{
moveToPosition = initialPosition;
cameraPositionInMain = true;
isViewChanged = false;
Debug.Log("Initial posiiton after second change: " + initialPosition.position);
Debug.Log(moveToPosition.position);
}
}
And here is what it does in editor: