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 Red Sentinel · Jan 04, 2013 at 11:52 AM · camerarotatecharacter controller

Character controls seen in Amnesia

Hi everyone. How would I make my fps camera rotate slightly to the right or left like it does in Amnesia when you press "q" or "e" for looking round corners? Think of it as touching your ear to your shoulder if you haven't played Amnesia before. I am fairly new to scripting so I need some help. All input is appreciated, thanks.

Edit : You can see the action here http://www.youtube.com/watch?v=Fu8A8i8x26k at 11:49 to 11:52.

Comment
Add comment · Show 6
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 AlucardJay · Jan 06, 2013 at 05:30 AM 1
Share

Do you have a video link as an example for people who don't know or havn't played Amnesia?

avatar image Red Sentinel · Jan 06, 2013 at 06:55 AM 0
Share

Just look up "Amnesia : the Dark Decent" on youtube and you should see it on just about the first one you look at.

avatar image AlucardJay · Jan 06, 2013 at 07:31 AM 1
Share

If you are asking for help, do you think it is fair to make me search to help you? And how do you know what I am watching is the movement you are after?

For example, note how the OP of this question gave all the information needed to help : http://answers.unity3d.com/questions/374134/quake-like-movement.html

avatar image Red Sentinel · Jan 06, 2013 at 07:39 AM 0
Share

I apologise, I meant no disrespect. You can see the action here http://www.youtube.com/watch?v=Fu8A8i8x26k at 11:49 to 11:52.

avatar image AlucardJay · Jan 06, 2013 at 07:58 AM 0
Share

Thanks, a picture (or video) is a thousand words. Here is a question on leaning that may help : http://forum.unity3d.com/threads/162847-Camera-rotation-quot-lean-quot

Show more comments

4 Replies

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

Answer by AlucardJay · Jan 06, 2013 at 09:55 AM

Sorry if the comments seemed harsh, after posting many mod comments, it is just easier to get help if all the information is supplied up front. I did find this interesting, and after searching for look around corner and lean, there really is no immediate answer out there. So I have had a go at writing something to answer your question.

Disclaimer : I have a very hard time with rotations !

this mostly works. There is a jump if you lean left then lean right straight away, and if you rotate the camera then it breaks (may do odd things), but this is the best I could come up with for my skill level :

 #pragma strict
 
 var leanAngle : float = 35.0;
 var leanSpeed : float = 5.0;
 var leanBackSpeed : float = 6.0;
 
 function Update () 
 {
     if (Input.GetKey("q")) {
        LeanLeft();
     }
     
     else if (Input.GetKey("e")) {
        LeanRight();
     }
     
     else
     {
         LeanBack();
     }
 }
 
 function LeanLeft() 
 {
     // current Z-rotation
     var currAngle : float = transform.rotation.eulerAngles.z;
     //var rot : Quaternion = transform.rotation;
     
     // target Z-rotation
     var targetAngle : float = leanAngle;
     
     if ( currAngle > 180.0 )
     {
         //targetAngle = 0.0 - leanAngle;
         currAngle = 360 - currAngle;
     }
     
     //lerp value from current to target
     var angle : float = Mathf.Lerp( currAngle, targetAngle, leanSpeed * Time.deltaTime );
     
     //Debug.Log ( "Left : currAngle " + currAngle + " : targetAngle " + targetAngle + " : angle " + angle );
     
     // rotate char
     var rotAngle : Quaternion = Quaternion.Euler( transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, angle );
     transform.rotation = rotAngle;
 }
 
 function LeanRight() 
 {
     // current Z-rotation
     var currAngle : float = transform.rotation.eulerAngles.z;
     
     // target Z-rotation
     var targetAngle : float = leanAngle - 360.0;
     
     if ( currAngle > 180.0 )
     {
         targetAngle = 360.0 - leanAngle;
     }
     
     //lerp value from current to target
     var angle : float = Mathf.Lerp( currAngle, targetAngle, leanSpeed * Time.deltaTime );
     
     //Debug.Log ( "Right : currAngle " + currAngle + " : targetAngle " + targetAngle + " : angle " + angle );
     
     // rotate char
     var rotAngle : Quaternion = Quaternion.Euler( transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, angle );
     transform.rotation = rotAngle;
     
 }
 
 function LeanBack() 
 {
     // current Z-rotation
     var currAngle : float = transform.rotation.eulerAngles.z;
     
     // target Z-rotation
     var targetAngle : float = 0.0;
     
     if ( currAngle > 180.0 )
     {
         targetAngle = 360.0;
     }
     
     //lerp value from current to target
     var angle : float = Mathf.Lerp( currAngle, targetAngle, leanBackSpeed * Time.deltaTime );
     
     //Debug.Log ( "Center : currAngle " + currAngle + " : targetAngle " + targetAngle + " : angle " + angle );
     
     var rotAngle : Quaternion = Quaternion.Euler( transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, angle );
     transform.rotation = rotAngle;
 }


The link I provided was the best I could find, but the code in there doesn't work I found out! The rotations always left the character facing forward.

Comment
Add comment · Show 3 · 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 Red Sentinel · Jan 06, 2013 at 10:44 AM 0
Share

Great thanks, but how do I make it so the player doesn't move left or right unless they press a or d?

avatar image AlucardJay · Jan 07, 2013 at 06:25 AM 0
Share

I don't understand the question. With this script, the player doesn't move when leaning, just rotates on the Z_axis. Watch what the controller does when you press q/e. I noticed the collider stays upright, so there may even be a chance that the player won't get hit by collisions if looking around the corner.

avatar image epikdude70alt · Apr 06, 2014 at 07:15 PM 0
Share

Put on FPC to us it correctly...

avatar image
-2

Answer by fajarazizlaksono · Jan 06, 2013 at 01:50 PM

wow yamimash ... i like him XD , come to the mash , everytime i open youtube just to see him...

sorry I did not answer your question, the answer is readily available above,

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
avatar image
0

Answer by MarkFinn · Jan 04, 2013 at 02:32 PM

This will depend somewhat on how you control your camera now.

Assuming that you use "transform.LookAt(playerCharacter.transform)" or similar you could simply add an offset to the lookAt target.

Very crude example follows.

 using UnityEngine;
 using System.Collections;
 
 public class lookatit : MonoBehaviour {
     
     public GameObject target;
     
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         if (target!=null)
         {
             if (Input.GetKey(KeyCode.Q)){transform.LookAt(target.transform.position+new Vector3(3, 0, 0));}
             else if (Input.GetKey(KeyCode.E)){transform.LookAt(target.transform.position+new Vector3(-3, 0, 0));}
             else{transform.LookAt(target.transform.position);}
         }
     }
 }
Comment
Add comment · Show 3 · 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 Red Sentinel · Jan 04, 2013 at 08:29 PM 0
Share

What do I put as the target?

avatar image MarkFinn · Jan 05, 2013 at 10:05 AM 0
Share

The player character you want the camera o look at, or just replace it entirely with a point in the middle of the room/scene if you are working with a game where the camera doesn't usually move.

avatar image Red Sentinel · Jan 05, 2013 at 10:43 AM 0
Share

What I want to be able to do is rotate the camera to the side slightly so the player is able to look around any corner at any time. Say if you were trying to touch your ear to your shoulder. This is what I am trying to achieve.

avatar image
0

Answer by D12Duke1 · Aug 02, 2016 at 12:00 PM

A bit old on the answer, but lerping the camera is a horrible way of trying to 'lean' the camera.. It's unreliable for precision.

What I did, goofing around just now taking a break from my neverending bloody project...

I created a 'lean left' and 'lean right' camera and I parented them to my main camera at 0 0 0, from there when I did a simple do-tween to -.04 -.002, -.008 for left and copy pasted it for right removing the negative values.. On 'Q' press down or 'E' press down, it will switch to that camera, play the lean animation (woot for mixamo!) on the character and commit to the dotween. It was figity as hell so i through a rigidbody on it and gave it .2 drag and froze position. The end result was very close to Rainbow Six Ravenshield peaking. i 'spose i could upload a video of how I did it.. I used playmaker.

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

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

Look to the side-Scripting Problem 2 Answers

I am getting a problem with moving and rotating a camera! 1 Answer

Scripting Issue With Top Down Mouse Movement 1 Answer

How do I rotate a Rigidbody to a surface normal AND use camera rotation? 1 Answer

Rotate charcter with camera? 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