Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
avatar image
0
Question by seatoskyhk · Apr 01, 2015 at 04:19 PM · rotationz-axishit.point

How to rotate a gameObject towards a hit point along Z axis?

my camera is on Z axis.. all of my objects are on the x-y pane.

so, i have a game object with an arrow sprite pointing up. I want to have that arrow head pointing towards the hit point.

I have a function that is called upon Raycasthit is known:

      Quaternion toHitRotation = Quanternion.FromToRotation(hit.point, Vector3.forward) * this.transform.rotation;
      this.transform.rotation = toHItRotation;

however, it doesn't work. I check the gameobject, instead of having x & y being zero, now, there are values in x & y, and things get weird. I tried to "normalized" by adding:

      this.transform.rotation = this.transform.rotation * Quanternion.Euler(0,0,90);

and still doesn't work.

what did I do wrong?

Comment
Add comment · Show 2
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 KdRWaylander · Apr 02, 2015 at 07:45 AM 0
Share

Is your camera position (0,0,0) ? Because putting a point position (hit.point) gives in fact the vector between (0,0,0) and your point. What you want to do is something like hit.point - Camera.main.transform.position (this assumes that the camera your using has the tag "$$anonymous$$ain Camera").

An other (and easier imo) solution is to use 'just' transform.LookAt(hit.point); on your gameobject and job is done :) You may have to add an offset to the rotation (like +180 degrees) if your gameobject is not facing the good direction.

avatar image seatoskyhk · Apr 02, 2015 at 07:55 AM 0
Share

Thanks. .Let me try the 2nd solution. :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rogodoy · Mar 31, 2021 at 01:28 PM

 transform.LooKAt(hit.point);
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

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 stop rotation in x and y axis??? 2 Answers

Rotation eulerangles not adjusting correctly... 2 Answers

Trouble - Limit rotation on Z-axis 0 Answers

Rotate object like a safe dial 0 Answers

Unity Mouse Look Script Issue 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