Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by ninjaboynaru · Dec 18, 2013 at 11:13 PM · 2drotationaxisrotate objectface

2D Rotate object so y axis faces other object

I have a 2D missile. I need to rotate the missile so that the top/tip of the missile is facing the player. The player is the alien ship. The missile is the blue and red thing.

Here is an image below of the current situation.

I need to rotate around the z axis to get the top to point towards the alien but when ever I use transform.LookAt or quaternion.LookRotation it always makes the flat side face the alien, not the top/tip of the missile

alt text

help1.png (39.0 kB)
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
1
Best Answer

Answer by Spinnernicholas · Dec 18, 2013 at 11:44 PM

Do this:

 transform.LookAt(transform.position + new Vector3(0,0,1), target);

You can still use the lookat function, you always want the sprite to "lookat" the camera(along the z axis for xy plane). But, you angle it so that the up vector points at your target.

This is assuming that the top of the missile is the top of the sprite.

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 ninjaboynaru · Dec 19, 2013 at 12:21 AM 0
Share

Code above worked but slight modification. Thanks

transform.LookAt(transform.position + new Vector3(0,0,1), target.transform.position - transform.position)

avatar image MuradD · Mar 20, 2016 at 06:42 PM 0
Share

Assets/scripts/bullet.js(95,21): BCE0023: No appropriate version of 'UnityEngine.Transform.LookAt' for the argument list '(UnityEngine.Vector3, UnityEngine.Transform)' was found.

idk how can I make my bullet look at the smoke co$$anonymous$$g out from its back (clone prefab)

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D - Rotate object based on touch moved (diff between touches) 0 Answers

Tracking the object in the 2D game 0 Answers

Rotating a Sprite to face mouse / target? 2 Answers

Rotating an object on Z axis while moving 1 Answer

Player Arm will not rotate when moving with Xbox Joystick 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