FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál
  • ✇Recent Questions - Game Development Stack Exchange
  • Stop an object from rotating past a certain rotation value in UnityZeid Tisnes
    Learning how to program in Unity, so bare with me. I'm making a game called Flappy Bird and I'm having issues with my z-rotation boundaries. Let's say I have some gameObject (call it Bird) that goes up and falls down from the y-axis. However, I want this bird, when it goes down, the z-axis rotates clockwise (so negative rotation). Once it starts falling down, the z-values in the rotation ramps from 0 to -90 in float values. Now, my bird should not keep spinning but stay fixed to the limit until
     

Stop an object from rotating past a certain rotation value in Unity

Learning how to program in Unity, so bare with me. I'm making a game called Flappy Bird and I'm having issues with my z-rotation boundaries. Let's say I have some gameObject (call it Bird) that goes up and falls down from the y-axis. However, I want this bird, when it goes down, the z-axis rotates clockwise (so negative rotation). Once it starts falling down, the z-values in the rotation ramps from 0 to -90 in float values. Now, my bird should not keep spinning but stay fixed to the limit until I start flying again. When I make my fly action, the bird should reset the z-rotation back to 0 in a gradual manner, not -45 to 0 immediately.

From what I have achieved, there was no luck for me to stop the spin on the bird. It is just continuously spinning without stopping from the range I want. My range is from 0 to -45 z-axis rotation.enter image description hereenter image description here

I have tried to play around with the transformation of my z values to get an idea, but nada. From what I have gathered and tried, I was playing around with the eulerAngles values, Rigidbody.freezeRotation(), transform.Rotate() method, and even the Quanterion.Euler() method.

here is the code function example I'm making:

public float zTest;
public Vector3 movementDirection;

private void FallSpeed()
{
    movementDirection.y +=  my_gravity * Time.deltaTime; //my_gravity is set to -9.81f
    transform.position += movementDirection * Time.deltaTime;
    zTest += 1 * movemenntDirection.y;
    transform.rotation = Quaternion.Euler(0, 0, zTest);
    if ((transform.rotation.z >= -45.0f && transform.rotation.z <= 0.0f))
    {
        transform.Rotate(0, 0, zTest); //I have a feeling this is completely bad, but I was trying to reset my rotation values.
        // transform.rotation = Quaternion.Euler(0, 0, zTest); //Another way I was trying it
        // currentEuler = new Vector3(transform.rotation.x, transform.rotation.y, -69); //Another way I was trying it
    }
}

To be honest, a lot of reading documentation made me more confused in how this interaction is happening and I'm not fully thinking straight at this point. Anyone has suggestions in tackling this problem or pointing me to the right direction? If anything, I will make more edits if needed for clarification and documentation for myself and others.

❌
❌