Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug LookAtConstraint rotation affected by worldUpObject's position and not rotation?

Discussion in 'Animation Rigging' started by daniel_lochner, Jan 12, 2022.

  1. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    Hi there,

    I've assigned a transform to the
    worldUpObject
    field of a
    LookAtConstraint
    component as shown below:
    upload_2021-12-16_18-18-44.png

    Why is it that changing the position of the
    worldUpObject
    in relation to the object on which this constraint is attached, affects its rotation? Should it not just depend on the rotation of the
    worldUpObject
    ? Rotating the
    worldUpObject
    actually doesn't seem to affect the rotation at all, so am I misunderstanding something?

    I originally posted this question in the animation sub-forum.

    Thanks,
    Daniel
     
    Last edited: Jan 12, 2022
  2. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    Hi, I am working on something similar to this and noticed a 'cross affective' on two gameobjects instead of just one. I just narrowed down the test to clarify. I have the parent object rotation being effected by the child rotation. I am hoping its a coding mistake on my part and then your post popped up.
    Forgive me I am not trying to highjack. This post came at the correct time for my efforts. I am curious as to what you find out based upon your description. I have 12 years of Unity so when these oddball scenarios pop up I follow closely.
     
  3. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
  4. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    I would be careful when using a Look At Constraint in an Animation Rigging setup. Look At Constraint is a native Unity constraint is evaluated after animation has finished. In comparison, the Animation Rigging constraints are animation playable driven constraints and are evaluated by the Animator directly. Depending on your workflow, you might want to use one or the other, but mix & matching may cause issues.

    https://docs.unity3d.com/2022.2/Documentation/Manual/Constraints.html

    The best equivalent in Animation Rigging right now would be MultiAimConstraint.

    Otherwise, reading from the LookAtConstraint documentation, the worldUpObject is used to calculate the up vector for the constraint. So, it's going to take the direction from the game object to the world up object. Rotating the world up object won't do anything.

    https://docs.unity3d.com/2022.2/Documentation/Manual/class-LookAtConstraint.html
     
  5. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    170
    Ah interesting. Thanks @simonbz! Never knew that LookAtConstraint wasn't apart of the Animation Rigging package -- because of the similar naming convention. Will have to look into the MultiAimConstraint. On an aside note: Is there any way we can access the implementation of the LookAtConstaint? I just need really simple LookAt functionality, however, whatever I try, using the built-in LookAt function achieves undesirable results for game objects with scaling and different offset rotations etc. Would really appreciate it! :)
     
  6. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    Unfortunately, that is not possible. While the Animation Rigging source code is available, the `LookAtConstraint` is a native constraint in Unity core and I can't legally share that source code.

    However, it appears that `LookAtConstraint` and `AimConstraint` share the same implementation. The difference being that `LookAtConstraint` is a simplified constraint with fewer parameters.

    The `MultiAimConstraint` has a similar implementation. So I think it's a fair point of comparison.