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 scarletsnake · Jan 22, 2016 at 08:02 PM · rotationoffsetthird-person-camera

Third Person Camera Rotation Offset Trouble

Hey guys;

I've a very basic TPS camera (its a free-floating camera that tracks the character's position and is controlled by mouse movement, standard TPS camera for games like MGSV), have integrated a lot of stuff into it, one part that keeps eluding me is how to make the character stay in the left side of the center of the camera at all times. The offset value that i input works great until I turn the camera 180 degrees, then the character is placed on the right side of the camera. I've read on some forums here that this is because of localRotation, but just couldn't wrap my head around how I'd make it work... Here's the code that does the rotation;

 function LateUpdate () {
 if (Time.timeScale == 1){
 if (Input.GetButtonDown ("ChangeCam")){
 if (camMode == 'close'){camFar();
 }else{
 camClose();
 }}
 var desiredAngle = target.transform.eulerAngles.y;
 
    x += Input.GetAxis("Mouse X") * xSpeed * 0.02 ;
         y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
         y = ClampAngle(y, yMinLimit, yMaxLimit);
          targetOffset = Vector3(1,1.2,0);       
         var rotation = Quaternion.Euler(y, x, 0);
         var targetPos = target.position + targetOffset;
         var direction = rotation * -Vector3.forward;
 
       var targetDistance = AdjustLineOfSight(targetPos, direction);
       currentDistance = Mathf.SmoothDamp(currentDistance, targetDistance, distanceVelocity, closerSnapLag * .3);
     transform.rotation = rotation ;
     transform.localPosition = targetPos + direction  * currentDistance;
 
 }}

This part of the camera code is based on the platformer demo that came with Unity 2.x installations. I realize that this question was asked quite a few times, but none of the solutions worked for me. Can you please advise on what to change or how to proceed?

Thanks in advance;

Jon

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

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

38 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

Related Questions

Limit Rotation of Camera around a player using keyboard 1 Answer

Mimic other object's rotation on one axis (with offset) 0 Answers

Third Person Camera on a speherical world 2 Answers

Rotate object with different timing...? 1 Answer

Changing Animation Rotation offset 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