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 /
avatar image
0
Question by zak666 · Aug 15, 2016 at 10:18 PM · scriptingbasicsscritping

transform.rotation = Quaternion.Slerp "freaks out doesn't acutely track game object.

this should work, after 4 seconds the camera should look at and track my object, instead it freaks out to the side and jitters until you stop the scene.

 using UnityEngine;
 using System.Collections;
 
 public class CameraControlla : MonoBehaviour {
 
 
     public float TimerOne = 0f;
     private float rotationSpeed = 12;
     public bool CameraCall1 = false;
     public bool CameraCall2 = false;
     public GameObject target;
     public GameObject target2;
     // Update is called once per frame
 
     void Update () {
         
         TimerOne += 1 * Time.deltaTime;
 
 
         if (TimerOne > 4) {
             CameraCall1 = true;
         }
 
         if (TimerOne > 8) {
             CameraCall1 = true;
         }
 
         if(CameraCall1 == true){
             // Track
             transform.rotation = Quaternion.Slerp(target.transform.rotation, Quaternion.LookRotation(target.transform.position - transform.position ), Time.deltaTime * rotationSpeed);
         }
 
 
         if(CameraCall2 == true){
             // Track
             transform.rotation = Quaternion.Slerp(target2.transform.rotation, Quaternion.LookRotation(target2.transform.position - transform.position ), Time.deltaTime * rotationSpeed);
 
     }
 }
 
 
 }
 
 
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 Yujingping · Aug 16, 2016 at 02:35 AM

Hey there. Let's focus on this sentence:

  transform.rotation = Quaternion.Slerp(target.transform.rotation, Quaternion.LookRotation(target.transform.position - transform.position ), Time.deltaTime * rotationSpeed);

What this does, is to set the rotation of your camera from the rotation of your TARGET to the direction from your camera to the target. Obviously this is not what you wanna to do, so why does this cause a freaking effect?

Let's split the process and analyze step by step: 1. The rotation of your camera is set to the spherical interpolation of the rotation of your target and the direction that you actually want to face. Namely, now the camera's rotation is roughly the same with your TARGET. And you can see a transition from the original rotation to the new rotation. 2. The Update function is called again, but since the rotation of your target actually doesn't change at all, the rotation of your camera is set to that of your target again. And then, transit again.

Hence, the view of camera freaks and doesn't stop trembling at a "strange angle".

So where is your error? Simply change that sentence to this:

 transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.transform.position - transform.position ), Time.deltaTime * rotationSpeed);

Now the rotation of the camera is really updated based on its own rotation, and you can see a smooth transition from its original angle to another. Basically when you wanna to Interpolate a value and change it continuously, the value should appear in the first parameter of the Lerp function to make sense.

Lastly just mention that your CameraCall2 will never be set in the script provided.

Please feel free for further questions.

GL & HF!

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

53 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 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 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

need help on prefab spawning 1 Answer

Script error about the semicolon. 1 Answer

instantiating prefabs from array 1 Answer

What is Mono? Is it a compiler? A language? Or what? 3 Answers

What is Vector3, Vector4, etc.? 2 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