U
U
Uncle Bogdan2021-09-03 16:54:19
Unity
Uncle Bogdan, 2021-09-03 16:54:19

Why doesn't smooth turn work?

I want to smoothly open the door, but for some reason the code does not work

using UnityEngine;

public class Door : MonoBehaviour
{
    [SerializeField] private int _angle;
    [SerializeField] private Transform _root;

    [SerializeField] private State _state;

    enum State
    {
        Standart,
        Open,
    }

    private void OnMouseDown()
    {
        if(_state == State.Standart)
        {
            _root.eulerAngles = Vector3.Lerp(transform.eulerAngles, transform.eulerAngles + Vector3.up * _angle, 1000);

            _state = State.Open;
        }
        else
        {
            _root.eulerAngles = Vector3.Lerp(transform.eulerAngles, transform.eulerAngles - Vector3.up * _angle, 1000);

            _state = State.Standart;
        }
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2021-09-03
@GavriKos

Learn the concepts of "game cycle", "update" and that's it.

P
pashara, 2021-09-06
@pashara

Yes, because it's spelled wrong.
To make something move smoothly, you need to execute the code so that every frame it moves the door in the right way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question