- Home /
Question by
SlimDoughnut · Feb 15 at 08:12 PM ·
rotationcharacter movement
Need help making Resident Evil style quick turn
My game has fixed camera angles similar to the early resident evil titles and I've been having trouble creating a quick turn action. I got some code that I thought would work but my character barely rotates if at all.
My Code:
private Coroutine LookCoroutine;
[SerializeField]
private float quickTurnTime = 5f;
void Update()
{
if (Input.GetKeyDown(KeyCode.Q) && isWalking == false)
{
StartRotating();
}
}
public void StartRotating()
{
if (LookCoroutine != null)
{
StopCoroutine(LookCoroutine);
}
LookCoroutine = StartCoroutine(LookAt());
}
private IEnumerator LookAt()
{
Vector3 rot = transform.rotation.eulerAngles;
rot = new Vector3(rot.x, rot.y + 180, rot.z);
float time = 0f;
while (time < 1)
{
transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(rot), Time.deltaTime * time);
time += Time.deltaTime * quickTurnTime;
yield return null;
}
}
Would appreciate some feedback on how to make this work and if it can and should be done another way.
Comment
Your answer