Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
2
Question by Nic 1 · Oct 12, 2010 at 04:24 AM · lookat

LookAt but without z axis?

Hi,

I want use a tranform.lookat function for look an object but with a different z rotation?

Plz Thank you Sry for my bad english

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

6 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by duck · Oct 12, 2010 at 09:15 AM

There's no version of LookAt which operates on a different axis.

To get around this, you can either:

a) rotate the object after performing the LookAt, like so:

transform.LookAt( target );
transform.Rotate( -90, 0, 0 );

or,

b) make your visible object the child of a "dummy" empty game object, and rotate the child object by 90 degrees in the desired direction. Then perform the LookAt function on the empty parent game object.

hope this helps!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
7

Answer by Max Kaufmann · Nov 04, 2010 at 07:21 AM

Z-Rotation, globally, determines the "up" direction (twisting around the line-of-sight axis). So, easy, just pass in the current up vector as the optional second argument:

transform.LookAt(target, transform.up);
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image OreoSplitter · Mar 04, 2018 at 07:18 PM 0
Share

Thank you! What worked for me is using another objects transform with the transform.up so I could use it's axis without needing to be a child object.

avatar image Zephirka · Dec 17, 2021 at 10:03 AM 0
Share

Worked like a charm, just put my camera up and text lined up horizontally

avatar image
2

Answer by Pixeye · Jan 29, 2011 at 07:25 AM

I assume you're making 2d game?

You can use something like that

var targetPoint: GameObject // gameobject to look to

   function Update()
         {

         transform.LookAt(targetPoint);
         transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0); // lock x and z axis to zero
         }

Try using transform.eulerAngles . With that you can also lock your Z axis to other different degree. For example :

 transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 75); 

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Twayne · Nov 02, 2010 at 08:30 AM

If you mean you want the LookAt feature but leave z fixed say z = fixedZ, I was able to do this with

transform.LookAt(Vector3(target.position.x , target.position.y , fixedZ)); 

or if you want the z to stay level with the transform

transform.LookAt(Vector3(target.position.x , target.position.y , transform.position.z));
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by wicked208 · Apr 26, 2011 at 05:39 PM

http://forum.unity3d.com/threads/36377-transform.LookAt-or-Quaternion.LookRotation-on-1-axis-only

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make the front, left, right, or the back of a gameobject look at a target? 1 Answer

enemy look at GameObject player? unity ver. 5.2 C# 0 Answers

How do i make my enemy look at player on only one axis? 1 Answer

Shader Graph: Rotate texture to look at 'camera' 1 Answer

Help for Realistic car Chase/Pursuit 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges