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 Black_D0g_z · May 26, 2013 at 01:27 PM · cameramovementpan

how to stop making script constantly want to look at the vector

Ok so I made a camera script that will pan over whatever you right click on but if i move the camera the script still wants to look at that spot so makes panning the camera impossible. How to I make it stop caring once it has looked there? I tried putting it in the right click statement which works but it never finishes the rotation to where I clicked which is its own issue.

Here is my JS script so far:

 #pragma strict
     var rotationSpeed: float = 5;
     var target : Transform;
     var hit : RaycastHit;
     @script AddComponentMenu("Camera-Control/Mouse Orbit")
 
 function Start () {
 
 }
 
 function Update () {
 
     if(Input.GetMouseButton(1)) {
 
         var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if(Physics.Raycast(ray, hit))
         Debug.Log("Mouse Location " + hit.point);
         Debug.Log("camera Location " + Camera.mainCamera.gameObject.transform.position);
         Debug.Log("mouse coord X =" + Input.GetAxis("Mouse X"));
         Debug.Log("camera Rotation" + Camera.mainCamera.transform.rotation);
         //roatation system working if points are stored and start point is created when script load for starting position for each map.
         
     }
     
         Camera.mainCamera.transform.rotation = Quaternion.Slerp(Camera.mainCamera.transform.rotation, Quaternion.LookRotation(hit.point - Camera.mainCamera.gameObject.transform.position), rotationSpeed*Time.deltaTime);
 }
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

2 Replies

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

Answer by robertbu · May 26, 2013 at 02:12 PM

You need to put in a flag and turn off the tracking when the camera is pointed in the right direction. I've used 'tracking' for the boolean flag these mods to your code:

 #pragma strict
     var rotationSpeed: float = 5;
     var target : Transform;
     var hit : RaycastHit;
     @script AddComponentMenu("Camera-Control/Mouse Orbit")
     private var tracking = false;
  
 function Update () {
  
     if(Input.GetMouseButton(1)) {
  
         var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if(Physics.Raycast(ray, hit))
         Debug.Log("Mouse Location " + hit.point);
         Debug.Log("camera Location " + Camera.mainCamera.gameObject.transform.position);
         Debug.Log("mouse coord X =" + Input.GetAxis("Mouse X"));
         Debug.Log("camera Rotation" + Camera.mainCamera.transform.rotation);
         tracking = true;
         //roatation system working if points are stored and start point is created when script load for starting position for each map.
  
     }
    if (tracking) {
            var q = Quaternion.LookRotation(hit.point - Camera.mainCamera.gameObject.transform.position);
         Camera.mainCamera.transform.rotation = Quaternion.Slerp(Camera.mainCamera.transform.rotation, q, rotationSpeed*Time.deltaTime);
         if (Quaternion.Angle(Camera.mainCamera.transform.rotation, q) < 0.1) {
           tracking = false;
           Debug.Log("Tracking Done");
         }
     }
 }
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 Black_D0g_z · May 26, 2013 at 07:28 PM 0
Share

This is more what im looking for now a few adjustments and i should get it to work exactly how i need. Thanks!

avatar image
0

Answer by NineSpin · May 26, 2013 at 02:28 PM

hm... maybe because you are telling the camera to rotate towards this point constantly (it is un update function), you should simply move line 25. into the if statement of your function as so:

  if(Input.GetMouseButton(1)) {
  
         var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if(Physics.Raycast(ray, hit))
         Debug.Log("Mouse Location " + hit.point);
         Debug.Log("camera Location " + Camera.mainCamera.gameObject.transform.position);
         Debug.Log("mouse coord X =" + Input.GetAxis("Mouse X"));
         Debug.Log("camera Rotation" + Camera.mainCamera.transform.rotation);
         //roatation system working if points are stored and start point is created when script load for starting position for each map.
  Camera.mainCamera.transform.rotation = Quaternion.Slerp(Camera.mainCamera.transform.rotation, Quaternion.LookRotation(hit.point - Camera.mainCamera.gameObject.transform.position), rotationSpeed*Time.deltaTime);
     }
  so your camera rotates only when clicked.

         
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 Black_D0g_z · May 26, 2013 at 07:27 PM 0
Share

This will not work. I did state that i tried this and it does not finish tracking the camera.

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

14 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

Related Questions

RTS Camera Rotation and Movement 0 Answers

movement disable when camera changes view 1 Answer

Move camera forward/backwards with mouse wheel 1 Answer

Final Fantasy style camera 1 Answer

Constraining a camera movement 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