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 karma0413 · Feb 05, 2015 at 11:13 AM · camerarotationquaternionfromtorotation

Rotation, my script shouldn't work but does.

LOL. I guess the title says it all. I am doing rotations on objects to face towards their intended target. I had borrowed some of this logic and it seemed to work perfectly on my camera tracking, but it is using the same code and I can't figure out why my fromDirection should be based off my UICamera.

UICAMERA, sits at 0,0,0 and does not rotate and is not attached to any ships flying around. In fact, this camera is pretty much hidden except to view the UI Overlay stuff.

THISSCRIPT and the SpaceShip its attached to is at something like -7000,4,0

The SUCCESSFUL CODE IS:

     void TurnTowardsTheTargetVector ()
     {
         //if we are not in position
         Vector3 Point = myTarget.transform.position;
         // Direction to something = target.position - start.position
         Vector3 toDirection = Point - transform.position;
         Vector3 fromDirection = GameObject.FindGameObjectWithTag ("UICamera").transform.forward;
         
         
         Quaternion toRotation = Quaternion.FromToRotation(fromDirection,toDirection);
         transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, turningInertia * Time.deltaTime);
 
         
 
 
 
     }
 

it shouldn't work but does...

In the Above code, which is part of a larger script that is attached to a spaceship. And it flies around automatically. And when the user clicks a "planet" it [the spaceship] aligns to it. My Confusion is because as I imagine in my mind. The fromDirection should be the transform.forward of the spaceship..... Why in the hell is UICamera even involved or even working perfectly? (as far as I can tell). If anything I would have thought the MainCamera ( which is actually following behind the spaceship ) would have been the issue. I would have thought this code BELOW was the solution:

 Vector3 fromDirection = this.transform.forward;


Where THIS, is actually just the spaceship gameobject. When I do however use the this.transform.forward code it kind of works, but only halfway. In fact, literally the camera tracks to about halfway.

I have done Debug.Drawrays on (toDirection) and (this.transform.forward) and they are both right on target.

Comment
Add comment · Show 1
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 karma0413 · Feb 05, 2015 at 04:41 AM 0
Share

SOLVED - I changed the code just a bit, and It works perfectly

But what am I not understanding ? =(

... and IT ALSO makes sense to me. But, I ask you all what is it that I am not UNDERSTANDING.... my initial post makes no sense to me.. but this does; This is the newcode:

     Quaternion toRotation = Quaternion.LookRotation(myTarget.transform.position - transform.position);
             transform.rotation = Quaternion.Slerp(transform.rotation, toRotation, 0.5f * Time.deltaTime);
 

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Checking for quaternion values to not be NaN 4 Answers

Camera Rotation Question 1 Answer

A little help with this camera script please? 3 Answers

Lerp Third Person Camera Rotation 1 Answer

camera rotation apparent to player 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