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 spitu · Apr 03, 2013 at 03:40 PM · camerapositionsavetargeting

How to save position of camera

I have a third person camera that can orbit around the player and(when needed) reposition and lock itself behind the player for targeting purposes. I want to make it so when switching from targeting to orbit the camera will keep the position and not snap back to the orbit position it had.

 void UpdatePosition()
     {
         if(!Targeting2.Instance.isTargeting)
         {
             var posX = Mathf.SmoothDamp(position.x, desiredPosition.x, ref velX, X_Smooth);
             var posY = Mathf.SmoothDamp(position.y, desiredPosition.y, ref velY, Y_Smooth);
             var posZ = Mathf.SmoothDamp(position.z, desiredPosition.z, ref velZ, X_Smooth);
             position = new Vector3(posX, posY, posZ);
         
         transform.position = position;
         transform.LookAt(TargetLookAt);
     }
     else if(Targeting2.Instance.isTargeting)
     {
         var posX = Mathf.SmoothDamp(position.x, desiredPosition.x, ref velX, X_TSmooth);
         var posY = Mathf.SmoothDamp(position.y, desiredPosition.y, ref velY, Y_TSmooth);
         var posZ = Mathf.SmoothDamp(position.z, desiredPosition.z, ref velZ, X_TSmooth);
         position = new Vector3(posX, posY, posZ);
         
         transform.position = position;
         transform.LookAt(TargetLookAt);
     }
 }
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 dendens2 · Apr 03, 2013 at 07:06 PM 0
Share

Can't you just save the position to a variable, and then when you need to snap back just set the position to the variable.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Apr 03, 2013 at 07:10 PM

Somewhere (not in the snippet you have) you are computing desiredPosition. For orbit, it's probably based on an orbit-angle variable.

When you switch into Orbit mode, also reset that angle to 0 (or whatever number means forwards.)

Comment
Add comment · Show 2 · 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 spitu · Apr 03, 2013 at 09:30 PM 0
Share

if(Targeting2.Instance.isTargeting) desiredPosition = Player.transform.TransformPoint(0, 15, -20); else desiredPosition = CalculatePosition(mouseY, mouseX, Distance);

This is what I have for calculating desiredPosition. So what your saying I should do is make desiredPosition reset to the istargeting position whenever I switch over. I have tried setting the desiredPosition just before I calculate it but is doesn't seem to work It still goes back to the old position.

avatar image Owen-Reynolds · Apr 04, 2013 at 10:37 PM 0
Share

"setting the desiredPosition just before I calculate it...goes back to the old position": Right. It's recomputed each frame from mouseX and mouseY, so those are what they reset.

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

12 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

Related Questions

Position far away from center of map generates artifacts 1 Answer

Place a object in front the camera in the coordinate 0 of Y axis 2 Answers

How to rotate the camera to the gameobject position. 3 Answers

How do I translate around a circle? 3 Answers

How to move camera up and down 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