Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 DeadKenny · Aug 03, 2015 at 09:09 AM · camerainputrotateaxislocal

Space Camera Issue.

How to get this clamped input on the local axis, so when I rotate in space(where there is no up or down) it works properly. What happens is that angleF rotates the player along the z axis so when that happens the input and camera still thinks there is up and down so input is made opposite... need that to be stopped!!

         if(controlable){                        
                 angleH += Mathf.Clamp(Input.GetAxis("Mouse X"), -1, 1) * horizontalAimingSpeed * Time.deltaTime;                            
                 angleV += Mathf.Clamp(Input.GetAxis("Mouse Y"), -1, 1) * verticalAimingSpeed * Time.deltaTime;
 
                 angleV = Mathf.Clamp(angleV, minVerticalAngle, maxVerticalAngle);
                
             //if(zeroG == true){
                 angleF += Mathf.Clamp(Input.GetAxis("Yaw"), -1, 1) * horizontalAimingSpeed * Time.deltaTime; // 
             //}
             }
 //        }        
                 
         // Set aim rotation... this is the part where it gets set.           
             Quaternion aimRotation = Quaternion.Euler(-angleV, angleH, angleF);
             Quaternion camYRotation = Quaternion.Euler(0, angleH, 0);
             
             camera.rotation = aimRotation;
         




Setting the final rotation on local axis does not work.

I need to get that input in the Space.Self basically.

Comment
Add comment · Show 2
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 Runalotski · Aug 03, 2015 at 04:15 PM 0
Share

What are you useing to make the rotation because that is missing from your code. i.e Transform.rotate() or rotation = quaternion

avatar image DeadKenny · Aug 03, 2015 at 04:19 PM 0
Share

Ok will update with more of the code... 1$$anonymous$$. Updated!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Runalotski · Aug 03, 2015 at 07:26 PM

Okay I have got this

 //set veribales to zero each frame so that it will only read a number
 //when the mouse moves
 float angleH = 0f, angleV = 0f, angleF = 0f;
 
     if(controlable){                        
                      angleH += Mathf.Clamp(Input.GetAxis("Mouse X"), -1, 1) * horizontalAimingSpeed * Time.deltaTime;                            
                      angleV += Mathf.Clamp(Input.GetAxis("Mouse Y"), -1, 1) * verticalAimingSpeed * Time.deltaTime;
      
                      angleV = Mathf.Clamp(angleV, minVerticalAngle, maxVerticalAngle);
                     
                  //if(zeroG == true){
                      angleF += Mathf.Clamp(Input.GetAxis("Yaw"), -1, 1) * horizontalAimingSpeed * Time.deltaTime; // 
                  //}
                  }
      //        }        
                      
              // Set aim rotation... this is the part where it gets set.
              //these two are now not needed
                  Quaternion aimRotation = Quaternion.Euler(-angleV, angleH, angleF);
                  Quaternion camYRotation = Quaternion.Euler(0, angleH, 0);
 
 //change this line from .rotation to .rotate
                  Camera.main.transform.Rotate(-angleV, angleH, angleF, Space.Self);


Comment
Add comment · Show 6 · 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 DeadKenny · Aug 03, 2015 at 07:37 PM 0
Share

Ok this kinda screws things up for me, BUT it fixes the axis thing.The rest of the code gets screwed because now it does not pivot.

However it still helps so thanks. I will up vote.

avatar image Runalotski · Aug 03, 2015 at 07:40 PM 0
Share

what do you mean it does not pivot?

avatar image DeadKenny · Aug 03, 2015 at 08:17 PM 0
Share

Its a 3rd person camera which rotates around the player. The camera position does not change when using this new rotate.

Don't know why, the aimRotation is used but never changed. The rotation of the camera itself is not used by any of camera position code, but but stops it from working.

I will post the rest of the code.

avatar image DeadKenny · Aug 03, 2015 at 08:26 PM 0
Share
 //This is where the camera changes position for 3rd person view.
                     smoothPlayerPos = Vector3.Lerp(smoothPlayerPos, player.position, smoothingTime * Time.deltaTime);
                     smoothPlayerPos.x = player.position.x;
                     smoothPlayerPos.z = player.position.z;
                     Vector3 farCamPoint = smoothPlayerPos + camYRotation * pivot + aimRotation * camOffset;
                     Vector3 closeCamPoint = player.position + camYRotation * closeOffset;
                     float farDist = Vector3.Distance(farCamPoint, closeCamPoint);
                             
                 
                     maxCamDist = $$anonymous$$athf.Lerp(maxCamDist, farDist, 5 * Time.deltaTime);
                     
                     // $$anonymous$$ake sure camera doesn't intersect geometry
                     // This is to check if intersects with something...
                     RaycastHit hit;
                     Vector3 closeToFarDir = (farCamPoint - closeCamPoint) / farDist;
                     float padding = 0.3f;
                     if (Physics.Raycast(closeCamPoint, closeToFarDir, out hit, maxCamDist + padding, ~camLayer$$anonymous$$ask)) {
                         maxCamDist = hit.distance - padding;
                     }
                 
                     currCamPose = closeCamPoint + closeToFarDir * maxCamDist;             
                     camParent.transform.position = transform.position;   
                     cam.position = currCamPose; //Here is the final position code....
                                 
                 
 
avatar image Runalotski · Aug 03, 2015 at 09:28 PM 0
Share

make a new gameobject called pivot and child this to you character

now child the main camera to the pivot game object where ever you want

now attach your rotate camera script to the pivot game object and it will make the camera orbit it

what i mean is make the pivot rotate ins$$anonymous$$d of the camera

Show more comments

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

23 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

Related Questions

UnityException: Input Axis Rotate is not setup. 2 Answers

use world axis when using transform.rotate 3 Answers

Wrong Camera axis after "zoom" to GameObject 0 Answers

use world axis when using transform.rotate 0 Answers

Rotate Camera on axis and X axis not working 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