- Home /
Question by
Ajay2008 · Jul 26, 2020 at 01:13 AM ·
c#quaternionslerp
My Quaternion rotation happens instantly
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveCamera : MonoBehaviour
{
private Vector3 Target;
private Vector3 cameraStartPosition;
private bool isLerping;
public float Speed;
public float speed;// Quaternion speed
public float timer;
public float CameraPanTime;
public Quaternion targetRotation;
void Start()
{
CameraPosition1();
CameraPosition2();
}
public void CameraPosition1()
{
isLerping = true;
cameraStartPosition = transform.position;
Target = new Vector3(30f, 2.5f, -5f);
}
public void CameraPosition2()
{
isLerping = true;
cameraStartPosition = transform.position;
Target = new Vector3(30f, 15f, 200f);
}
void FixedUpdate()
{
if (isLerping)
{
timer += Time.deltaTime;
transform.position = Vector3.Lerp(cameraStartPosition, Target, timer / CameraPanTime);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.time / CameraPanTime);
}
}
}
Here is my script for my camera to lerp between 2 positions, but when I start the game my camera rotation instantly changes. Whats the issue?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613004102im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rotating Armature During Animation 1 Answer
Distribute terrain in zones 3 Answers
Slerp Rotation Problem 2 Answers
i want to get my to cube to rotate 90 degrees on the x-axis as it jumps 0 Answers
few question about quaternion slerp 3 Answers