#Quaternion.LookRotation

1 messages · Page 1 of 1 (latest)

tired burrow
#

I am trying to create a 'dip' affect on an object that causes it to tip downwards after time (I am creating a flappy bird clone for learning).
I recently started learning about how Unity understands rotations and so i've happened upon Quaternion.LookRotation.

I've attached an image with two drawings, one for an object at time = 0, and another for an object at time = z (which just indicates any amount of time has passed).

It seems to me that when the unity documentation uses the word "look" in the explanation of what 'forward' is, it means that 'forward' direction of the object?

Can Quaternion.LookRotation. be used to control the angle of an object (lets say, tip the point of a diamond downwards 45 degrees)?
Do i understand what this method does?

novel light
#

Have you tried it out

sleek plinthBOT
#

Try it!

Whenever you ask "can I do X" or "will Y work", the only thing you are doing is wasting time (including your own!)
The people you're asking aren't computers, humans can be wrong in their answers. We also don't have access to your project or know your intentions.
The only way to know if something works as you wanted it to, is to try it for yourself!

tired burrow
#

I haven't, I looked into it more and realized its a dead end. I just got excited when I found it and wanted to ask before I went to work, sorry about that!

tired burrow
#

I read online it wasn't very good for Unity 2D which is what I am using

#

I am trying to figure out, basically, how to take an object which is angled at 0 degrees (looking forward) and make it look at -90 degrees (looking down)

#

It sounds so simple, but every Quaternion related thing I use causes the object to spin out of control

#

I've tried making the object rotate a small amount for every amount of time that passes, but it looks blocky and I can't seem to get it to stop at -90 degrees

#

I tried righting an if statement that basically say:

#

if (rotationAngle >= -90) {rotate the object}

#

because in my head, as long as the object was greater than -90, it would rotate downwards, and then when it got to -90, it would stop

tired burrow
#
    float objectRotation;
    float counter = 0;
    public float effectRate; // rate at which I want the if statement to trigger
    Vector3 angleCap = new Vector3(0,0,-90);

    // Start is called before the first frame update
    void Start()
    {
        objectRotation = transform.rotation.z ; // Initialize the vector representing the rotation. Its hard coded as 0,0,0 here, which coincidently is the default position of the sprite.
    }

    // Update is called once per frame
    void Update()
    {

        if (counter >= effectRate)
        {
            if (objectRotation >= -90)// I think I am close with my set-up here, I need to make the if statement based on the value of transform.rotation.z, but am having trouble....
            {
                transform.Rotate(0, 0, -30, Space.World);//rotate the game object -30 degrees
            } 

             counter = 0; //Set counter back to 0
        }
        counter += Time.deltaTime; //make sure the counter is actually keeping track of time.
#

Here is an example of my code

#

I think I have a couple problems here, #1, I initialize the objectRotation as a float based on my objects default position/rotation for the z axis

#

and then in my nest if statement, I make a comparison

#

0 is always >= -90

#

so like, my if statement doesn't mean anything

#

I need to be updating the objectRotation value in real time, that way when it does = -90, the if statement can fail

#

But I don't know how to do that I guess

novel light
tired burrow
#

Well thanks