Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by Abdou23 · Mar 07, 2016 at 05:09 PM · 2d rotationlook at

2D (look at) object disappears

I have a moving object that I want to look at the target it's moving towards, here is my code:

  void Update()
  {
      transform.LookAt( target.transform.position);
  }

The problem is the object does look at the target while moving, but since the game is in 2D view, the object kinda turns sideways, what is happening is that it turns and faces the object it's looking at.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Glurth · Mar 07, 2016 at 05:34 PM

Not sure, but it sound like you need to specify the LookAt function with the "up" direction. If you are using a 2D space this will be the coordinate you are NOT using. So if you are using x, and z for the 2D space, specify the lookAt "up" parameter using new Vector3(0,1,0) (if using x and y for your 2D space, then specify (0,0,1) for "up")

Note: by default, if you DON'T provide the "up" direction, it will use Vector3.up=(0,1,0) [so, if you ARE using X and Z in your 2D space, this answer is NOT the solution.]

Edit:
Some more detail about using the LookAt Function: This is a function that can take one OR two parameters. If you only give it one; it will automatically pass a "default" value (for LookAt, the default value is Vector3.up). http://docs.unity3d.com/ScriptReference/Transform.LookAt.html

Since the lookat function deals with 3D vectors, you may need to specify the second parameter yourself.

When you "look at" something, in the real world, and tilt your head, you are changing the second parameter for the LookAt Function.

If you use the wrong value for this "head tilt", in your 2D world, it might turn your object "into" the screen (and from the edge a 2D object is not visible since it has no thickness.)

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 Abdou23 · Mar 07, 2016 at 08:28 PM 0
Share

I don't really understand, could you please simplify things further?!

avatar image Abdou23 · Mar 08, 2016 at 09:27 PM 0
Share

Thank you.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Hi Friends, I am a beginner in Unity world also I am crawling child in C#.. I want to Flip My Character According to My Touch Position left or right.. Now I can flip character but not according the touch its just flip whenever i touch.. 0 Answers

I can't seem to rotate my character depending on what side he is running to (2D sidescroller) 0 Answers

How to make a 2D rigidbody vertically when input is via the gyroscope 0 Answers

Beginner Question about moving 0 Answers

How to Transform.Rotate Around with the rotation of the controller right stick 0 Answers


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