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 Elowan · Oct 05, 2013 at 05:54 PM · camerarotateaxisdistancemove

Wrong Camera axis after "zoom" to GameObject

       void Update()
     {    
         // If Alt+linke mouse, Zoom + center to GameObject (Cursor)
         if(Input.GetMouseButton(0)&& Input.GetKey(KeyCode.LeftAlt)){  
       
             Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
             RaycastHit hit;    
             
          if(Physics.Raycast(ray, out hit)){
     
             //Debug.Log("hit something at "+hit.distance+" Meter");
                 
         // Camera to GameObj,hit.point
         Camera.main.transform.LookAt(hit.point);
                 
         // Camera move to GameObj, hit.distance
         Camera.main.transform.Translate(Vector3.forward*(hit.distance-10));    
             }
             
     else{
                 return;            
 }
     }
         }

Hi there, i´m pretty new to Unity and C# and just glad to get some script running...

But it does not quiete work, like it should. There are to main things:

  1. The Camera too quikly "jumps" onto the clicked GameObject. Would be nicer, if it would just go there a bit slower.

  2. And most important: After transforming the Cam to Object, the Cam-Axis are a bit strange. After some more clicks, the zoom is at minimum (but i did not zoom with wheel).

When i rotate the Cam, it´s y-Axis is just not straight like before. And it starts to get XYZ Rotation, which i don´t want.

The Cam should just center on a clicked GO and the move close to it (but maintain the right world axis)

Help anybody?

Comment
Add comment · Show 5
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 meat5000 ♦ · Oct 05, 2013 at 06:50 PM 0
Share

Look at Lerp functions for smooth movement. It is simple enough to Zero the rotations after the movement; you won't notice it in the game.

avatar image Elowan · Oct 05, 2013 at 09:07 PM 0
Share

Thx, i tried to Zero Out with Camera.main.transform.Rotate (0,0,0); and it seems to work.

Can you give an example for lerp? Unity is a Bit Short nö some good example Code

How do i correct the zoom issue?

avatar image GambinoInd · Oct 05, 2013 at 10:48 PM 0
Share

For lerp, here's the documentation and an example: LERP

avatar image Cherno · Oct 05, 2013 at 11:03 PM 0
Share

Here's another, more generic, example for Lerp.

 var $$anonymous$$oveSpeed : float;
 
 function $$anonymous$$ove()
 {
      var StartPosition : Vector3 = transform.position;
      var EndPosition : Vector3;//where the object should end up at
         
      var t : float = 0.0;
           
      while (t < 1.0) 
      {
           t += Time.deltaTime * $$anonymous$$oveSpeed;
       transform.position = Vector3.Lerp(StartPosition, EndPosition, t);
       yield;
      }
 }
 


However, ins$$anonymous$$d of moving the camera towards an object, you can also use the camera's own "zoom" (actually it is it's field of view:

 camera.fieldOfView +=5;//for zoo$$anonymous$$g in a bit

Also, take a look here for a complete camera script with moving and zoo$$anonymous$$g.

http://answers.unity3d.com/questions/549572/3d-rts-camera.html

avatar image Elowan · Oct 07, 2013 at 06:46 PM 0
Share

U$$anonymous$$PF - the Zeroing-Out of the unwanted rotations (that i get, after the "lookAT") are not handled by my attempt.

How can i set the camera to rotate and move in "Wordl-Space" again, ins$$anonymous$$d of "around the LookAt´t Gameobject") ??

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

18 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

Related Questions

I am getting a problem with moving and rotating a camera! 1 Answer

Move and Rotate on a fixed axis? 1 Answer

Top-Down Camera Trouble 1 Answer

Space Camera Issue. 1 Answer

camera move x axis 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