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 /
  • Help Room /
avatar image
0
Question by CalisIAm · Oct 22, 2015 at 08:27 PM · camerarotation3d

3D - Move this player lean script (Leaning to the right) to the left. (EASY)

Hello!

I have this older lean script that only works when going to the right. What I want to know, is how I can make it move to the left instead.

So the code below angles/moves/rotates the camera to the right, so the player can see past walls and such. All I need is, it go to the left instead.

Keep in mind it is not the full code, so if you want that to test it out or use the script yourself, please ask.

 if(Input.GetKey(KeyCode.E)) {
         isLeaning = true;
         
         if(curLean < leanSize) {
             Camera.main.transform.Translate(leanSpeed * Time.deltaTime, 0, 0);
             if(leanSize > 0.6) {
                 Camera.main.transform.Rotate(0, 0, leanSpeed * Time.deltaTime * -1 * leanAngle);
             }
             curLean += leanSpeed * Time.deltaTime;
         }
     }
     if(Input.GetKeyUp(KeyCode.E)) {
         isLeaning = false;
     }

 if(curLean > 0.01 && (!isLeaning)) {
         Camera.main.transform.Translate(leanSpeed * Time.deltaTime * -1, 0, 0);
         Camera.main.transform.Rotate(0, 0, leanSpeed * Time.deltaTime * 1 * leanAngle);
         curLean -= leanSpeed * Time.deltaTime;
     }
Comment
Add comment · Show 7
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 toromano · Oct 22, 2015 at 08:42 PM 1
Share

Did you try reversing Rotate and Translate Vectors?

      Camera.main.transform.Translate(-leanSpeed * Time.deltaTime, 0, 0);
      Camera.main.transform.Rotate(0, 0, leanSpeed * Time.deltaTime  * leanAngle);

avatar image CalisIAm · Oct 22, 2015 at 08:51 PM 0
Share

@toromano

If I add what you add it will rotate to the right way, but after I release the key it will move the player to where the camera lean was.

However it does work correctly to the right side, making me think I should add another part of the code that I didnt think was relevant. So could you re-check my code up above. Ill change it now.

avatar image toromano CalisIAm · Oct 22, 2015 at 09:03 PM 0
Share

Hımm This might do:

 if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.Q)) {
          isLeaning = true;
          
          if($$anonymous$$athf.Abs(curLean) < leanSize) {
              Camera.main.transform.Translate(-leanSpeed * Time.deltaTime, 0, 0);
              if(leanSize > 0.6) {
                  Camera.main.transform.Rotate(0, 0, leanSpeed * Time.deltaTime * leanAngle);
              }
              curLean -= leanSpeed * Time.deltaTime;
          }
      }
      if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.Q)) {
          isLeaning = false;
      }
 
  if($$anonymous$$athf.Abs(curLean) > 0.01 && (!isLeaning)) {
          Camera.main.transform.Translate(leanSpeed * Time.deltaTime * -1, 0, 0);
          Camera.main.transform.Rotate(0, 0, leanSpeed * Time.deltaTime * 1 * leanAngle);
          curLean -= leanSpeed * Time.deltaTime;
      }



avatar image CalisIAm toromano · Oct 22, 2015 at 09:11 PM 0
Share

That sadly makes it just move forever indefinitely. Isnt it something to do with the if statement I added later on? See$$anonymous$$gly thats what the if statement that runs when you stop leaning.

Show more comments

1 Reply

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

Answer by CalisIAm · Oct 22, 2015 at 09:52 PM

@toromano

Got it to work! Thanks! What we missed was to make the leanback if statement be seperate for left and right by making them functions. These functions are now called upon when the E or Q key get UP, so basically when you stop leaning.

This way I could simply change the 1, and -1 around, into -1, and 1 for it to work for the left side.

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Quaternion Roation Mouse Script 0 Answers

How do I get the current active camera? 2 Answers

How to bring UI element infront of other objects? 0 Answers

How to rotate a sprite after using LookAt in 3D 0 Answers

Unity3D accelerometer camera rotation realistic controls 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