Monday, October 24, 2022
HomeGame Developmentc# - Cease an object from rotating previous a sure rotation worth...

c# – Cease an object from rotating previous a sure rotation worth in Unity


Studying the right way to program in Unity, so naked with me. I am making a recreation known as Flappy Fowl and I am having points with my z-rotation boundaries. To illustrate I’ve some gameObject (name it Fowl) that goes up and falls down from the y-axis. Nevertheless, I would like this fowl, when it goes down, the z-axis rotates clockwise (so adverse rotation). As soon as it begins falling down, the z-values within the rotation ramps from 0 to -90 in float values. Now, my fowl shouldn’t maintain spinning however keep fastened to the restrict till I begin flying once more. After I make my fly motion, the fowl ought to reset the z-rotation again to 0 in a gradual method, not -45 to 0 instantly.

From what I’ve achieved, there was no luck for me to cease the spin on the fowl. It’s simply repeatedly spinning with out stopping from the vary I would like. My vary is from 0 to -45 z-axis rotation.enter image description hereenter image description here

I’ve tried to mess around with the transformation of my z values to get an thought, however nada. From what I’ve gathered and tried, I used to be enjoying round with the eulerAngles values, Rigidbody.freezeRotation(), rework.Rotate() methodology, and even the Quanterion.Euler() methodology.

right here is the code perform instance I am making:

public float zTest;
public Vector3 movementDirection;

non-public void FallSpeed()
{
    movementDirection.y +=  my_gravity * Time.deltaTime; //my_gravity is about to -9.81f
    rework.place += movementDirection * Time.deltaTime;
    zTest += 1 * movemenntDirection.y;
    rework.rotation = Quaternion.Euler(0, 0, zTest);
    if ((rework.rotation.z >= -45.0f && rework.rotation.z <= 0.0f))
    {
        rework.Rotate(0, 0, zTest); //I've a sense that is fully dangerous, however I used to be making an attempt to reset my rotation values.
        // rework.rotation = Quaternion.Euler(0, 0, zTest); //One other means I used to be making an attempt it
        // currentEuler = new Vector3(rework.rotation.x, rework.rotation.y, -69); //One other means I used to be making an attempt it
    }
}

To be trustworthy, a variety of studying documentation made me extra confused in how this interplay is going on and I am not absolutely considering straight at this level. Anybody has options in tackling this drawback or pointing me to the proper path? If something, I’ll make extra edits if wanted for clarification and documentation for myself and others.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments