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
-1
Question by gripingberry · Jan 04, 2015 at 04:36 PM · c#camerafpscamera-look

Camera Lean

I have made a script that is intended to make the camera lean using controls and effects similar to amnesia. Although when I attach the script to a camera it has no errors in the console but pressing q and e have no effect. Please help!! Thanks guys

Code:

 using UnityEngine;
 using System.Collections;
 
 public class Lean : MonoBehaviour {
 
     
     public float leanAngle = 35.0f;
     public float leanSpeed = 5.0f;
     public float leanBackSpeed = 6.0f;
     
     void  Update (){
         if (Input.GetKey(KeyCode.Q)) {
             LeanLeft();
         }
         
         else if (Input.GetKey(KeyCode.E)) {
             LeanRight();
         }
         
         else
         {
             LeanBack();
         }
     }
     
     void  LeanLeft (){
         // current Z-rotation
         float currAngle = transform.rotation.eulerAngles.z;
         //Quaternion rot = transform.rotation;
         
         // target Z-rotation
         float targetAngle = leanAngle;
         
         if ( currAngle > 180.0f )
         {
             //targetAngle = 0.0f - leanAngle;
             currAngle = 360 - currAngle;
         }
         
         //lerp value from current to target
         float angle = Mathf.Lerp( currAngle, targetAngle, leanSpeed * Time.deltaTime );
         
         //Debug.Log ( "Left : currAngle " + currAngle + " : targetAngle " + targetAngle + " : angle " + angle );
 
         // rotate char
         Quaternion rotAngle = Quaternion.Euler( transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, angle );
         transform.rotation = rotAngle;
     }
     
     void  LeanRight (){
         // current Z-rotation
         float currAngle = transform.rotation.eulerAngles.z;
         
         // target Z-rotation
         float targetAngle = leanAngle - 360.0f;
         
         if ( currAngle > 180.0f )
         {
             targetAngle = 360.0f - leanAngle;
         }
         
         //lerp value from current to target
         float angle = Mathf.Lerp( currAngle, targetAngle, leanSpeed * Time.deltaTime );
         
         //Debug.Log ( "Right : currAngle " + currAngle + " : targetAngle " + targetAngle + " : angle " + angle );
         
         // rotate char
         Quaternion rotAngle = Quaternion.Euler( transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, angle );
         transform.rotation = rotAngle;
         
     }
     
     void  LeanBack (){
         // current Z-rotation
         float currAngle = transform.rotation.eulerAngles.z;
         
         // target Z-rotation
         float targetAngle = 0.0f;
         
         if ( currAngle > 180.0f )
         {
             targetAngle = 360.0f;
         }
         
         //lerp value from current to target
         float angle = Mathf.Lerp( currAngle, targetAngle, leanBackSpeed * Time.deltaTime );
         
         //Debug.Log ( "Center : currAngle " + currAngle + " : targetAngle " + targetAngle + " : angle " + angle );
         
         Quaternion rotAngle = Quaternion.Euler( transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, angle );
         transform.rotation = rotAngle;
     }
     [RPC]
     void  Test (){}
 }
 
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 Kiwasi · Jan 04, 2015 at 07:10 AM 2
Share

@alucardj Its always odd seeing your own scripts come back to you, complete with your own comments and idiosyncratic member names. I think some people forget how small the internet community of Unity developers really is.

@gripingberry I suggest you learn to write a script first, before copying from the internet. The code is fine, its probably a set up error in the inspector. Some things to check:

  • Is the script actually attached to the GameObject

  • Are the values for the public fields in the inspector non zero

  • Is the component enabled?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Weird FPS Camera 0 Answers

I cannot see button on camera preview 1 Answer

Implement a "FreeLook view" 1 Answer

FPS Camera, Camera and Player conflicting... 1 Answer

I cant see my gun its clipping through my camera 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