A
A
Alexey Fobius2021-08-02 13:51:03
C++ / C#
Alexey Fobius, 2021-08-02 13:51:03

How to disable axis rotation?

I have an object whose rotation along the z axis I need to allow from time to time, I can’t figure out how to correctly refer to the Rigidbody in the script in order to change this parameter.

To make it easier to understand, I will give an example of changing the Is Kinematic parameter through a script . Something like this, is it possible to do the same with rotation lock?

GetComponent<Rigidbody>().IsKinematic = true;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Fobius, 2021-08-02
@phobious

Rigidbody rb;

void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

//запретить
rb.constraints = RigidbodyConstraints.FreezeRotationZ

//разрешить
rb.constraints = RigidbodyConstraints.None;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question