Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Custom LookAt Function Help

Discussion in 'Scripting' started by wbourassabennett, Jan 13, 2024.

  1. wbourassabennett

    wbourassabennett

    Joined:
    Apr 24, 2020
    Posts:
    17
    Hello!

    I'm trying to get a quaternion (or Euler, whichever is easiest / most performant) from 2 points in space, where the right component(red gizmo arrow) of the rotation is the direction of one point towards another with the forward component (blue gizmo arrow) facing upwards: where the up component (green gizmo arrow) is perpendicular to a flat plane. Essentially the result of a transform.LookAt() function where forward is right and up is forward.

    I'm using ECS (float3, lower-case quaternion), so I can't use external functions. I've included an image to hopefully make a little more clear what I'm trying to achieve.

    Thanks!
     

    Attached Files:

  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,401
    Ryiah likes this.
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,698
  4. wbourassabennett

    wbourassabennett

    Joined:
    Apr 24, 2020
    Posts:
    17
    The problem with LookRotation, is the forward vector is always the "z" component (the blue gizmo arrow on the object points towards the target), while what I am trying to achieve is have the "x" component (red gizmo arrow) point towards the target. Changing the world up parameter doesn't change this.
     
  5. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,401
    Then you just need to apply an additional rotation to the object after you've got your look rotation.
     
    Ryiah likes this.