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 JA_555 · Nov 10, 2014 at 07:17 AM · lookatquick

make transform.lookat go fast

Hello, here is the Unity Docs script to make an object look at an object. However, I want to take this further and make this object look at something very sensitively. For example if my cube moved on its x-axis 2 degrees, I want this object to move on its x-axis 200 degrees. What can I do?

 #pragma strict
 var Cube : Transform; 
 
     // Rotate the camera every frame so it keeps looking at the target 
     function Update() {
         transform.LookAt(Cube);
     }
Comment
Add comment · Show 3
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 AlwaysSunny · Nov 10, 2014 at 05:21 AM 0
Share

Your question doesn't make sense. The effect of transform.LookAt() is already immediate. I'm not sure you're using the word degrees correctly. A degree describes rotation.

avatar image JA_555 · Nov 10, 2014 at 06:59 AM 0
Share

Oh I though it was a measurement of temperature. No I mean degrees. If a cube rotates 2 degrees, I want the other object to rotate 200 degrees. Whenever the object this is looking at moves, this should look at it, but whatever it rotated by to keep looking at the object, I want that to be multiplied

avatar image MD_Reptile · Nov 10, 2014 at 07:28 AM 0
Share

the LookAt() method will not work in your case then. You need a custom LookAt that will add however much amplification you would like, so basically not a "LookAt" but a "RotateThis$$anonymous$$uchIfThisRotatesThis$$anonymous$$uch" kind of method. And the sarcastic attitude (although funny haha) won't help you get many answers here. But yeah you need to take the angle between the two objects (I think?) and then depending on that angle, have another object rotate to a certain angle. There is no clear answer to this question really, because it depends how your implementing all this stuff.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · Nov 10, 2014 at 09:21 PM

With rotations, it is easy to get what you ask for, and for it to not be what you really need. So here is some code that implements what you asked for:

 #pragma strict
 
 public var target : Transform;
 public var magnifier : float = 5.0;
 private var tracker : Transform;
 
 function Start() {
     tracker = new GameObject().transform;
     tracker.LookAt(target);
     transform.LookAt(target);
 }
 
 function Update() {
     tracker.position = transform.position;
     var dir = target.position - tracker.position;
     var qLook = Quaternion.LookRotation(dir);
     var qDelta = qLook * Quaternion.Inverse(tracker.rotation);
     
     var angle : float;
     var axis : Vector3;
     qDelta.ToAngleAxis(angle, axis);
     
     transform.rotation = Quaternion.AngleAxis(angle * magnifier, axis) * transform.rotation;
     tracker.LookAt(target);
 }

 

How it works: It uses an empty game object to track the target. It figure out the delta rotation necessary to look at the target. It converts the result to an angle/axis representation. Then it does an AngleAxis() rotation multiplying the 'angle' by a factor.

Comment
Add comment · Show 1 · 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 JA_555 · Nov 10, 2014 at 11:09 PM 0
Share

amazing, and thanks for the explanation

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

Mega Bug In Turret - Help 5 Answers

rotate on the Y axis 1 Answer

Talking to multiple NPC's 2 Answers

Shooting in the LookAt direction 1 Answer

Top-Down LookAt problem 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