[ad_1]
Learning tips on how to program in Unity, so naked with me. I’m making a recreation known as Flappy Bird and I’m having points with my z-rotation boundaries. Let’s say I’ve some gameObject (name it Bird) that goes up and falls down from the y-axis. However, I would like this chicken, when it goes down, the z-axis rotates clockwise (so unfavorable rotation). Once it begins falling down, the z-values within the rotation ramps from 0 to -90 in float values. Now, my chicken shouldn’t maintain spinning however keep fastened to the restrict till I begin flying once more. When I make my fly motion, the chicken 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 chicken. It is simply repeatedly spinning with out stopping from the vary I would like. My vary is from 0 to -45 z-axis rotation.
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 taking part in round with the eulerAngles
values, Rigidbody.freezeRotation(), remodel.Rotate()
technique, and even the Quanterion.Euler()
technique.
right here is the code operate instance I’m making:
public float zTest;
public Vector3 movementDirection;
personal void FallSpeed()
{
movementDirection.y += my_gravity * Time.deltaTime; //my_gravity is about to -9.81f
remodel.place += movementDirection * Time.deltaTime;
zTest += 1 * movemenntDirection.y;
remodel.rotation = Quaternion.Euler(0, 0, zTest);
if ((remodel.rotation.z >= -45.0f && remodel.rotation.z <= 0.0f))
{
remodel.Rotate(0, 0, zTest); //I've a sense that is utterly unhealthy, however I used to be making an attempt to reset my rotation values.
// remodel.rotation = Quaternion.Euler(0, 0, zTest); //Another approach I used to be making an attempt it
// presentEuler = new Vector3(remodel.rotation.x, remodel.rotation.y, -69); //Another approach I used to be making an attempt it
}
}
To be trustworthy, loads of studying documentation made me extra confused in how this interplay is occurring and I’m not absolutely considering straight at this level. Anyone has ideas in tackling this drawback or pointing me to the best route? If something, I’ll make extra edits if wanted for clarification and documentation for myself and others.
[ad_2]