Unity: transform.LookAt(target) not “looking at” target?Cloning Prefabs with Unity not workingDynamically...

Why were movies shot on film shot at 24 frames per second?

What does it mean to have a subnet mask /32?

Why did this happen to Thanos's ships at the end of "Avengers: Endgame"?

Why is 日本 read as "nihon" but not "nitsuhon"?

Was Tuvok bluffing when he said that Voyager's transporters rendered the Kazon weapons useless?

Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?

Defense against attacks using dictionaries

Why would the US President need briefings on UFOs?

How do I make distance between concentric circles equal?

Concatenation of the result of a function with a mutable default argument in python

Ask for a paid taxi in order to arrive as early as possible for an interview within the city

A list of proofs of "Coherent topoi have enough points"

Efficiently pathfinding many flocking enemies around obstacles

Why does The Ancient One think differently about Doctor Strange in Endgame than the film Doctor Strange?

Exctract year, month, day from datetime2

If I have a 16.67% fail rate (N=24) & I do another 24 tests, what is the likelihood that I get 0 fails by chance?

What is the evidence on the danger of feeding whole blueberries and grapes to infants and toddlers?

Why is Boris Johnson visiting only Paris & Berlin if every member of the EU needs to agree on a withdrawal deal?

Is a butterfly one or two animals?

On the feasibility of space battleships

Church Booleans

Vacuum collapse -- why do strong metals implode but glass doesn't?

Check in to 2 hotels at same location

How much code would a codegolf golf if a codegolf could golf code?



Unity: transform.LookAt(target) not “looking at” target?


Cloning Prefabs with Unity not workingDynamically Changing GameObject makes NullReferenceException(C# Unity)Player tag does not respond to AddForceWhy when drawing a box using LineRenderer the connected points of the lines is not complete?How to completely stop the camera from clipping into the groundPlayer light color he collects before checkpoint is getting reset when he restarts at checkpoint






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







6












$begingroup$


I have been troubleshooting a prefab for several hours and am out of ideas. It concerns a method that I thought I was comfortable with, transform.LookAt(target). I have this prefab:



enter image description here



As you can see, I verified that the registration points for the eyes are at the center of mass; I also verified that they rotate correctly for the X, Y and Z axes. That yellow ball you see is the target object and IS NOT inside the prefab.



I have tried two means to get the eyes to look at the target. The first is this script, and it caused the eyes to dart 90 degrees counter-clockwise about the y axis (which is very wrong). I applied this script to both eyes. Check it out:



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LookAt : MonoBehaviour
{
public Transform target = null;

// Update is called once per frame
void Update()
{
transform.LookAt(target);
}
}


And please, before you think it: Yes, I remembered to set the target object in the editor. You can see the eyes pointing to the side instead of the target:



enter image description here



I found this other script on the Unity documentation that didn't work at first, but then I changed "Rotation" to "LocalRotation", saw that I was close, reversed the "relativePos" vector, and it worked--but only about the y axis:



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LookAt : MonoBehaviour
{
public Transform target = null;

// Update is called once per frame
void Update()
{
Vector3 relativePos = transform.position - target.position;

// the second argument, upwards, defaults to Vector3.up
Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up;
transform.localRotation = rotation;

}
}


You can see here that it works in the XY plane at eye level, but take my word for it when I say the eyes cannot look up or down if I move the ball up or down:



enter image description here



How can I fix this so that the eyes always look at the target I need it to?
Thank you sincerely for your time.



EDIT: I fixed it by this sloppy additional rotation, but there has to be a better way:



void Update()
{
//transform.LookAt(target);

Vector3 relativePos = target.position - transform.position;

// the second argument, upwards, defaults to Vector3.up
Quaternion rotation = Quaternion.LookRotation(relativePos, new Vector3(0,1,0));
transform.rotation = rotation*Quaternion.Euler(0,90,0);
}


enter image description here










share|improve this question











$endgroup$





















    6












    $begingroup$


    I have been troubleshooting a prefab for several hours and am out of ideas. It concerns a method that I thought I was comfortable with, transform.LookAt(target). I have this prefab:



    enter image description here



    As you can see, I verified that the registration points for the eyes are at the center of mass; I also verified that they rotate correctly for the X, Y and Z axes. That yellow ball you see is the target object and IS NOT inside the prefab.



    I have tried two means to get the eyes to look at the target. The first is this script, and it caused the eyes to dart 90 degrees counter-clockwise about the y axis (which is very wrong). I applied this script to both eyes. Check it out:



    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class LookAt : MonoBehaviour
    {
    public Transform target = null;

    // Update is called once per frame
    void Update()
    {
    transform.LookAt(target);
    }
    }


    And please, before you think it: Yes, I remembered to set the target object in the editor. You can see the eyes pointing to the side instead of the target:



    enter image description here



    I found this other script on the Unity documentation that didn't work at first, but then I changed "Rotation" to "LocalRotation", saw that I was close, reversed the "relativePos" vector, and it worked--but only about the y axis:



    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class LookAt : MonoBehaviour
    {
    public Transform target = null;

    // Update is called once per frame
    void Update()
    {
    Vector3 relativePos = transform.position - target.position;

    // the second argument, upwards, defaults to Vector3.up
    Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up;
    transform.localRotation = rotation;

    }
    }


    You can see here that it works in the XY plane at eye level, but take my word for it when I say the eyes cannot look up or down if I move the ball up or down:



    enter image description here



    How can I fix this so that the eyes always look at the target I need it to?
    Thank you sincerely for your time.



    EDIT: I fixed it by this sloppy additional rotation, but there has to be a better way:



    void Update()
    {
    //transform.LookAt(target);

    Vector3 relativePos = target.position - transform.position;

    // the second argument, upwards, defaults to Vector3.up
    Quaternion rotation = Quaternion.LookRotation(relativePos, new Vector3(0,1,0));
    transform.rotation = rotation*Quaternion.Euler(0,90,0);
    }


    enter image description here










    share|improve this question











    $endgroup$

















      6












      6








      6


      1



      $begingroup$


      I have been troubleshooting a prefab for several hours and am out of ideas. It concerns a method that I thought I was comfortable with, transform.LookAt(target). I have this prefab:



      enter image description here



      As you can see, I verified that the registration points for the eyes are at the center of mass; I also verified that they rotate correctly for the X, Y and Z axes. That yellow ball you see is the target object and IS NOT inside the prefab.



      I have tried two means to get the eyes to look at the target. The first is this script, and it caused the eyes to dart 90 degrees counter-clockwise about the y axis (which is very wrong). I applied this script to both eyes. Check it out:



      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;

      public class LookAt : MonoBehaviour
      {
      public Transform target = null;

      // Update is called once per frame
      void Update()
      {
      transform.LookAt(target);
      }
      }


      And please, before you think it: Yes, I remembered to set the target object in the editor. You can see the eyes pointing to the side instead of the target:



      enter image description here



      I found this other script on the Unity documentation that didn't work at first, but then I changed "Rotation" to "LocalRotation", saw that I was close, reversed the "relativePos" vector, and it worked--but only about the y axis:



      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;

      public class LookAt : MonoBehaviour
      {
      public Transform target = null;

      // Update is called once per frame
      void Update()
      {
      Vector3 relativePos = transform.position - target.position;

      // the second argument, upwards, defaults to Vector3.up
      Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up;
      transform.localRotation = rotation;

      }
      }


      You can see here that it works in the XY plane at eye level, but take my word for it when I say the eyes cannot look up or down if I move the ball up or down:



      enter image description here



      How can I fix this so that the eyes always look at the target I need it to?
      Thank you sincerely for your time.



      EDIT: I fixed it by this sloppy additional rotation, but there has to be a better way:



      void Update()
      {
      //transform.LookAt(target);

      Vector3 relativePos = target.position - transform.position;

      // the second argument, upwards, defaults to Vector3.up
      Quaternion rotation = Quaternion.LookRotation(relativePos, new Vector3(0,1,0));
      transform.rotation = rotation*Quaternion.Euler(0,90,0);
      }


      enter image description here










      share|improve this question











      $endgroup$




      I have been troubleshooting a prefab for several hours and am out of ideas. It concerns a method that I thought I was comfortable with, transform.LookAt(target). I have this prefab:



      enter image description here



      As you can see, I verified that the registration points for the eyes are at the center of mass; I also verified that they rotate correctly for the X, Y and Z axes. That yellow ball you see is the target object and IS NOT inside the prefab.



      I have tried two means to get the eyes to look at the target. The first is this script, and it caused the eyes to dart 90 degrees counter-clockwise about the y axis (which is very wrong). I applied this script to both eyes. Check it out:



      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;

      public class LookAt : MonoBehaviour
      {
      public Transform target = null;

      // Update is called once per frame
      void Update()
      {
      transform.LookAt(target);
      }
      }


      And please, before you think it: Yes, I remembered to set the target object in the editor. You can see the eyes pointing to the side instead of the target:



      enter image description here



      I found this other script on the Unity documentation that didn't work at first, but then I changed "Rotation" to "LocalRotation", saw that I was close, reversed the "relativePos" vector, and it worked--but only about the y axis:



      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;

      public class LookAt : MonoBehaviour
      {
      public Transform target = null;

      // Update is called once per frame
      void Update()
      {
      Vector3 relativePos = transform.position - target.position;

      // the second argument, upwards, defaults to Vector3.up
      Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up;
      transform.localRotation = rotation;

      }
      }


      You can see here that it works in the XY plane at eye level, but take my word for it when I say the eyes cannot look up or down if I move the ball up or down:



      enter image description here



      How can I fix this so that the eyes always look at the target I need it to?
      Thank you sincerely for your time.



      EDIT: I fixed it by this sloppy additional rotation, but there has to be a better way:



      void Update()
      {
      //transform.LookAt(target);

      Vector3 relativePos = target.position - transform.position;

      // the second argument, upwards, defaults to Vector3.up
      Quaternion rotation = Quaternion.LookRotation(relativePos, new Vector3(0,1,0));
      transform.rotation = rotation*Quaternion.Euler(0,90,0);
      }


      enter image description here







      unity rotation vector






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago







      hatinacat2000

















      asked 2 days ago









      hatinacat2000hatinacat2000

      2159 bronze badges




      2159 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          7











          $begingroup$

          The Problem:

          Your eyes default rotation makes them look to the negative X axis.

          However, Transform.LookAt() rotates the transform, so that the Transform.forward looks at the target.

          The Transform.forward always looks to the positive Z axis.

          (All directions in local space).



          Solution 1:

          Rotate the texture or mesh, so that the eye's default look direction is along the positive Z axis.

          Then LookAt will work as expected.



          Solution 2:

          After the call of Transform.LookAt, correct the rotation by the correct rotation.



          transform.LookAt(target);
          transform.rotation *= Quaternion.FromToRotation(Vector3.left, Vector3.forward);


          Where Vector3.left represents the default forward direction of the eyes.






          share|improve this answer








          New contributor



          Chillersanim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          $endgroup$















          • $begingroup$
            I tried rotating everything in the prefab so they were facing Z+ 10 min ago but that didn't do anything. Trying Solution 2...oh, lol! That's what I'm doing, isn't it! Good to know XD
            $endgroup$
            – hatinacat2000
            2 days ago








          • 1




            $begingroup$
            If you rotate it in the prefab, transform.lookat rotates it back. As your eye has the lookat directly, the rotation gets overwritten. You could achieve it though, by creating a game object with the LookAt script, and the eye as child. Then the rotation defined by you won't be overwritten.
            $endgroup$
            – Chillersanim
            2 days ago










          • $begingroup$
            That makes sense because then I don't need to apply the script to every monster in the game, it just needs to be in the arena. Would the eye no longer be in the prefab though? What do you mean "the eye as a child"?
            $endgroup$
            – hatinacat2000
            2 days ago












          • $begingroup$
            Well the parent game object with the LookAt is still part of the monster, as it is just put in between the monster and the eye. Or did I missunderstand something?
            $endgroup$
            – Chillersanim
            2 days ago










          • $begingroup$
            No, I was misunderstanding, I see what you mean now. I will try that. Thank you so much for your time and expertise!
            $endgroup$
            – hatinacat2000
            2 days ago














          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "53"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgamedev.stackexchange.com%2fquestions%2f174759%2funity-transform-lookattarget-not-looking-at-target%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          7











          $begingroup$

          The Problem:

          Your eyes default rotation makes them look to the negative X axis.

          However, Transform.LookAt() rotates the transform, so that the Transform.forward looks at the target.

          The Transform.forward always looks to the positive Z axis.

          (All directions in local space).



          Solution 1:

          Rotate the texture or mesh, so that the eye's default look direction is along the positive Z axis.

          Then LookAt will work as expected.



          Solution 2:

          After the call of Transform.LookAt, correct the rotation by the correct rotation.



          transform.LookAt(target);
          transform.rotation *= Quaternion.FromToRotation(Vector3.left, Vector3.forward);


          Where Vector3.left represents the default forward direction of the eyes.






          share|improve this answer








          New contributor



          Chillersanim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          $endgroup$















          • $begingroup$
            I tried rotating everything in the prefab so they were facing Z+ 10 min ago but that didn't do anything. Trying Solution 2...oh, lol! That's what I'm doing, isn't it! Good to know XD
            $endgroup$
            – hatinacat2000
            2 days ago








          • 1




            $begingroup$
            If you rotate it in the prefab, transform.lookat rotates it back. As your eye has the lookat directly, the rotation gets overwritten. You could achieve it though, by creating a game object with the LookAt script, and the eye as child. Then the rotation defined by you won't be overwritten.
            $endgroup$
            – Chillersanim
            2 days ago










          • $begingroup$
            That makes sense because then I don't need to apply the script to every monster in the game, it just needs to be in the arena. Would the eye no longer be in the prefab though? What do you mean "the eye as a child"?
            $endgroup$
            – hatinacat2000
            2 days ago












          • $begingroup$
            Well the parent game object with the LookAt is still part of the monster, as it is just put in between the monster and the eye. Or did I missunderstand something?
            $endgroup$
            – Chillersanim
            2 days ago










          • $begingroup$
            No, I was misunderstanding, I see what you mean now. I will try that. Thank you so much for your time and expertise!
            $endgroup$
            – hatinacat2000
            2 days ago
















          7











          $begingroup$

          The Problem:

          Your eyes default rotation makes them look to the negative X axis.

          However, Transform.LookAt() rotates the transform, so that the Transform.forward looks at the target.

          The Transform.forward always looks to the positive Z axis.

          (All directions in local space).



          Solution 1:

          Rotate the texture or mesh, so that the eye's default look direction is along the positive Z axis.

          Then LookAt will work as expected.



          Solution 2:

          After the call of Transform.LookAt, correct the rotation by the correct rotation.



          transform.LookAt(target);
          transform.rotation *= Quaternion.FromToRotation(Vector3.left, Vector3.forward);


          Where Vector3.left represents the default forward direction of the eyes.






          share|improve this answer








          New contributor



          Chillersanim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          $endgroup$















          • $begingroup$
            I tried rotating everything in the prefab so they were facing Z+ 10 min ago but that didn't do anything. Trying Solution 2...oh, lol! That's what I'm doing, isn't it! Good to know XD
            $endgroup$
            – hatinacat2000
            2 days ago








          • 1




            $begingroup$
            If you rotate it in the prefab, transform.lookat rotates it back. As your eye has the lookat directly, the rotation gets overwritten. You could achieve it though, by creating a game object with the LookAt script, and the eye as child. Then the rotation defined by you won't be overwritten.
            $endgroup$
            – Chillersanim
            2 days ago










          • $begingroup$
            That makes sense because then I don't need to apply the script to every monster in the game, it just needs to be in the arena. Would the eye no longer be in the prefab though? What do you mean "the eye as a child"?
            $endgroup$
            – hatinacat2000
            2 days ago












          • $begingroup$
            Well the parent game object with the LookAt is still part of the monster, as it is just put in between the monster and the eye. Or did I missunderstand something?
            $endgroup$
            – Chillersanim
            2 days ago










          • $begingroup$
            No, I was misunderstanding, I see what you mean now. I will try that. Thank you so much for your time and expertise!
            $endgroup$
            – hatinacat2000
            2 days ago














          7












          7








          7





          $begingroup$

          The Problem:

          Your eyes default rotation makes them look to the negative X axis.

          However, Transform.LookAt() rotates the transform, so that the Transform.forward looks at the target.

          The Transform.forward always looks to the positive Z axis.

          (All directions in local space).



          Solution 1:

          Rotate the texture or mesh, so that the eye's default look direction is along the positive Z axis.

          Then LookAt will work as expected.



          Solution 2:

          After the call of Transform.LookAt, correct the rotation by the correct rotation.



          transform.LookAt(target);
          transform.rotation *= Quaternion.FromToRotation(Vector3.left, Vector3.forward);


          Where Vector3.left represents the default forward direction of the eyes.






          share|improve this answer








          New contributor



          Chillersanim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          $endgroup$



          The Problem:

          Your eyes default rotation makes them look to the negative X axis.

          However, Transform.LookAt() rotates the transform, so that the Transform.forward looks at the target.

          The Transform.forward always looks to the positive Z axis.

          (All directions in local space).



          Solution 1:

          Rotate the texture or mesh, so that the eye's default look direction is along the positive Z axis.

          Then LookAt will work as expected.



          Solution 2:

          After the call of Transform.LookAt, correct the rotation by the correct rotation.



          transform.LookAt(target);
          transform.rotation *= Quaternion.FromToRotation(Vector3.left, Vector3.forward);


          Where Vector3.left represents the default forward direction of the eyes.







          share|improve this answer








          New contributor



          Chillersanim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.








          share|improve this answer



          share|improve this answer






          New contributor



          Chillersanim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.








          answered 2 days ago









          ChillersanimChillersanim

          3167 bronze badges




          3167 bronze badges




          New contributor



          Chillersanim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




          New contributor




          Chillersanim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

















          • $begingroup$
            I tried rotating everything in the prefab so they were facing Z+ 10 min ago but that didn't do anything. Trying Solution 2...oh, lol! That's what I'm doing, isn't it! Good to know XD
            $endgroup$
            – hatinacat2000
            2 days ago








          • 1




            $begingroup$
            If you rotate it in the prefab, transform.lookat rotates it back. As your eye has the lookat directly, the rotation gets overwritten. You could achieve it though, by creating a game object with the LookAt script, and the eye as child. Then the rotation defined by you won't be overwritten.
            $endgroup$
            – Chillersanim
            2 days ago










          • $begingroup$
            That makes sense because then I don't need to apply the script to every monster in the game, it just needs to be in the arena. Would the eye no longer be in the prefab though? What do you mean "the eye as a child"?
            $endgroup$
            – hatinacat2000
            2 days ago












          • $begingroup$
            Well the parent game object with the LookAt is still part of the monster, as it is just put in between the monster and the eye. Or did I missunderstand something?
            $endgroup$
            – Chillersanim
            2 days ago










          • $begingroup$
            No, I was misunderstanding, I see what you mean now. I will try that. Thank you so much for your time and expertise!
            $endgroup$
            – hatinacat2000
            2 days ago


















          • $begingroup$
            I tried rotating everything in the prefab so they were facing Z+ 10 min ago but that didn't do anything. Trying Solution 2...oh, lol! That's what I'm doing, isn't it! Good to know XD
            $endgroup$
            – hatinacat2000
            2 days ago








          • 1




            $begingroup$
            If you rotate it in the prefab, transform.lookat rotates it back. As your eye has the lookat directly, the rotation gets overwritten. You could achieve it though, by creating a game object with the LookAt script, and the eye as child. Then the rotation defined by you won't be overwritten.
            $endgroup$
            – Chillersanim
            2 days ago










          • $begingroup$
            That makes sense because then I don't need to apply the script to every monster in the game, it just needs to be in the arena. Would the eye no longer be in the prefab though? What do you mean "the eye as a child"?
            $endgroup$
            – hatinacat2000
            2 days ago












          • $begingroup$
            Well the parent game object with the LookAt is still part of the monster, as it is just put in between the monster and the eye. Or did I missunderstand something?
            $endgroup$
            – Chillersanim
            2 days ago










          • $begingroup$
            No, I was misunderstanding, I see what you mean now. I will try that. Thank you so much for your time and expertise!
            $endgroup$
            – hatinacat2000
            2 days ago
















          $begingroup$
          I tried rotating everything in the prefab so they were facing Z+ 10 min ago but that didn't do anything. Trying Solution 2...oh, lol! That's what I'm doing, isn't it! Good to know XD
          $endgroup$
          – hatinacat2000
          2 days ago






          $begingroup$
          I tried rotating everything in the prefab so they were facing Z+ 10 min ago but that didn't do anything. Trying Solution 2...oh, lol! That's what I'm doing, isn't it! Good to know XD
          $endgroup$
          – hatinacat2000
          2 days ago






          1




          1




          $begingroup$
          If you rotate it in the prefab, transform.lookat rotates it back. As your eye has the lookat directly, the rotation gets overwritten. You could achieve it though, by creating a game object with the LookAt script, and the eye as child. Then the rotation defined by you won't be overwritten.
          $endgroup$
          – Chillersanim
          2 days ago




          $begingroup$
          If you rotate it in the prefab, transform.lookat rotates it back. As your eye has the lookat directly, the rotation gets overwritten. You could achieve it though, by creating a game object with the LookAt script, and the eye as child. Then the rotation defined by you won't be overwritten.
          $endgroup$
          – Chillersanim
          2 days ago












          $begingroup$
          That makes sense because then I don't need to apply the script to every monster in the game, it just needs to be in the arena. Would the eye no longer be in the prefab though? What do you mean "the eye as a child"?
          $endgroup$
          – hatinacat2000
          2 days ago






          $begingroup$
          That makes sense because then I don't need to apply the script to every monster in the game, it just needs to be in the arena. Would the eye no longer be in the prefab though? What do you mean "the eye as a child"?
          $endgroup$
          – hatinacat2000
          2 days ago














          $begingroup$
          Well the parent game object with the LookAt is still part of the monster, as it is just put in between the monster and the eye. Or did I missunderstand something?
          $endgroup$
          – Chillersanim
          2 days ago




          $begingroup$
          Well the parent game object with the LookAt is still part of the monster, as it is just put in between the monster and the eye. Or did I missunderstand something?
          $endgroup$
          – Chillersanim
          2 days ago












          $begingroup$
          No, I was misunderstanding, I see what you mean now. I will try that. Thank you so much for your time and expertise!
          $endgroup$
          – hatinacat2000
          2 days ago




          $begingroup$
          No, I was misunderstanding, I see what you mean now. I will try that. Thank you so much for your time and expertise!
          $endgroup$
          – hatinacat2000
          2 days ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Game Development Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgamedev.stackexchange.com%2fquestions%2f174759%2funity-transform-lookattarget-not-looking-at-target%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...