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 Tyoma · Aug 04, 2012 at 07:30 PM · camerarotateoffset

Look to the side-Scripting Problem

I have looked everywhere and have yet to find a way to make it so that my 3rd person camera can rotate slightly left and right when I press a key...

I don't even have code that's failing because I don't know what code to use.

What I need is to have my camera's rotation offset (without moving my character) so that I can glance to the right and left of it. The important thing is to have the camera's rotation move back to its original position when I let go of the key(s).

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DNP · Aug 04, 2012 at 08:53 PM

Make a block on both sides, and one facing where the camera was originally looking, then do a code like this.

 var defaultPos : Transform;
 var target : Transform;
 var target2 : Transform;
 
 function Update(){
 if (Input.GetKeyDown(KeyCode.Q)){
 transform.LookAt(target);
 }
 
 if (Input.GetKeyUp(KeyCode.Q)){
 transform.LookAt(defaultPos);
 }
 
 if (Input.GetKeyDown(KeyCode.E)){
 transform.LookAt(target2);
 }
 
 if (Input.GetKeyUp(KeyCode.E)){
 transform.LookAt(defaultPos);
    }
 }
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 Tyoma · Aug 07, 2012 at 11:23 AM

I'm trying this with a flight simulator joystick and the only code that seems to have worked is

 public var Twist = 0.00;
 public var _twist = 0.00;
 public var maxTwist = 45;
 
 public var smooth = 2.0;
 
 function LateUpdate () {
 
 }
 
 function Update () {
 Twist =(Input.GetAxis("Twist")); //Joystick Axis 3Rd 
 twist();
 
 var target = Quaternion.Euler (0, _twist, 0);
 transform.rotation = Quaternion.Slerp(transform.rotation, target,
 Time.deltaTime * smooth);
 }
 
 function twist() {
 if (Twist > 0.9)
 _twist = maxTwist;
 
 if (Twist <= 0.9 && Twist > 0.8)
 _twist = (maxTwist * 0.9);
 
 if (Twist <= 0.8 && Twist > 0.7)
 _twist = (maxTwist * 0.8);
 
 if (Twist <= 0.7 && Twist > 0.6)
 _twist = (maxTwist * 0.7);
 
 if (Twist <= 0.6 && Twist > 0.5)
 _twist = (maxTwist * 0.6);
 
 if (Twist <= 0.5 && Twist > 0.4)
 _twist = (maxTwist * 0.5);
 
 if (Twist <= 0.4 && Twist > 0.3)
 _twist = (maxTwist * 0.4);
 
 if (Twist <= 0.3 && Twist > 0.2)
 _twist = (maxTwist * 0.3);
 
 if (Twist <= 0.2 && Twist > 0.1)
 _twist = (maxTwist * 0.2);
 
 if (Twist <= 0.1 && Twist >= -0.1)
 _twist = 0;
 
 if (Twist < -0.1 && Twist >= -0.2)
 _twist = -(maxTwist * 0.2);
 
 if (Twist < -0.2 && Twist >= -0.3)
 _twist = -(maxTwist * 0.3);
 
 if (Twist < -0.3 && Twist >= -0.4)
 _twist = -(maxTwist * 0.4);
 
 if (Twist < -0.4 && Twist >= -0.5)
 _twist = -(maxTwist * 0.5);
 
 if (Twist < -0.5 && Twist >= -0.6)
 _twist = -(maxTwist * 0.6);
 
 if (Twist < -0.6 && Twist >= -0.7)
 _twist = -(maxTwist * 0.7);
 
 if (Twist < -0.7 && Twist >= -0.8)
 _twist = -(maxTwist * 0.8);
 
 if (Twist < -0.8 && Twist >= -0.9)
 _twist = -(maxTwist * 0.9);
 
 if (Twist < -0.9)
 _twist = -maxTwist;
 }

It's great and all the only problem I have with this code is that the character moves along with the camera. It might be because I'm also using the default code that the 3rd person character/camera come with.

If anyone has any ideas as to how I can keep my character from rotating slightly with the camera I'd appreciate it.

Edit: It actually messes with the 3rd person camera script Soooo yeah.... ignore what I said about this code working.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Orbit 2D camera around circle but keep lookat towards z axis 1 Answer

Use lookAt and transform.translate at the same time 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

rotate camera on mobile 1 Answer

Character controls seen in Amnesia 4 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