• 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
Question by ColouredCarnival · Aug 02, 2015 at 01:35 PM · camerarotationcontrollerfollowpivot

Camera following Pivot not working

I want to make a t$$anonymous$$rdpersonshooter-camerascript
the player is the parent of an empty(pivot) and the camera should follow the pivot
camera

when i move my mouse to the left the player rotates to the left with the pivot but the problem lies with the camera:
it keeps the distance to the pivot but it doesnt inherit the rotation
(red is how the camera is, green is how the camera should be)
alt text
following the responsible part of the cameracontroller:

 //rotation of the camera
 transform.position = pivot.transform.position + (pivot.transform.rotation * (new Vector3 (0.5f,2,-2)));
 targetlook = Quaternion.LookRotation (pivot.transform.position - transform.position);
 transform.rotation = Quaternion.Slerp (transform.rotation, targetlook, smoothlook * Time.deltaTime);
 transform.LookAt (pivot.transform);  

any advice?

camerasetting1.jpg (15.0 kB)
camerasetting2.jpg (13.5 kB)
Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Runalotski · Aug 02, 2015 at 03:02 PM

make a new empty game object and call it pivot and then c$$anonymous$$ld it to the character

now make the camera a c$$anonymous$$ld of the pivot object,

now make a script that makes the pivot rotate with mouse movement and attach it to the pivot game object

you can the camera any distance and starting rotation you like it will rotate around the pivot game object.

Comment
ColouredCarnival

People who like this

1 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 ColouredCarnival · Aug 05, 2015 at 11:48 AM 0
Share

i did that but as long as this piece of code is active its the same case as above:
xRotation -= Input.GetAxis ("Mouse Y") * mousespeed;
xRotation = Mathf.Clamp (xRotation,-110,110);
transform.rotation = Quaternion.Euler (xRotation,0,0);

avatar image Runalotski · Aug 06, 2015 at 01:47 PM 0
Share

Dont set the rotaions you want to add to it

use

 transform.Roate(-Input.GetAxis ("Mouse Y") * mousespeed,0,0,space.self);
 transform.Roate(0,0,Input.GetAxis ("Mouse X") * mousespeed);

if you set the Rotation that is its absolute value in world coords so you are ignoring all rotations from the parent

Or

and this might be easier actualy

change your last line of code to

 transform.localRotation = Quaternion.Euler (xRotation,0,0);

but i have not tried this

avatar image ColouredCarnival · Aug 06, 2015 at 09:51 PM 0
Share

nice it works now :D
Thanks very much :DD

i use "transform.localRotation" and it works

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Camera not rotate when following player 1 Answer

Camera that sits behind player 2 Answers

Having a 3D text appear in the middle of the screen without using GUI (C#) 2 Answers

Minimap rotation 2 Answers

Spline controller problems? 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