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 theqtuber · Feb 26, 2012 at 10:52 PM · camerarotationplayery-axisfun

Rotation of Camera = Transform on the y-axis?

I am trying to make a script for a player controller. I have a small problem with the rotation though. I have a separate code to make the camera look around (sample program in Unity) and the camera can look around on every axis. Through programming I can't find a way to make the player model follow the camera on the y-axis. I made a simple line hoping it would work:

 transform.rotation.y = cam.rotation.y;

"transform" is the player model "cam" is the camera. It works, but not completely. The player model follows the camera correctly when the camera is from 0 to 180 degrees, but past that it follows the camera like a mirror (going from 180 to 0 as the camera goes from 180 to 360). I am so confused :'(

Thanks to anybody who helps.

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
3

Answer by aldonaletto · Feb 26, 2012 at 11:33 PM

transform.rotation is a Quaternion, and x, y and z have nothing to do with those nice and familiar angles shown in the Inspector/Rotation - these are the Euler angles.
You could try to use this:

   transform.eulerAngles = Vector3(0, cam.eulerAngles.y, 0);

The player will keep the horizontal plane, and follow the camera rotation around Y. But you may have problems because the Euler angles may show different combinations for the same rotation - like (0,180,0) or (180,0,180), for instance.
A better way to do what you want is to child the camera to the player, and attach the MouseLook.cs script to both - set the Axes field to Mouse X in the player's MouseLook, and to Mouse Y in the camera: Mouse X will rotate the player and the camera (because it's a player's child) around Y, and Mouse Y will rotate the camera only in the vertical plane.

Comment
Add comment · Show 1 · 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 BangPoulsen · Nov 12, 2012 at 03:46 PM 0
Share

Well i've tried the child thing you said and the camera and model are following each other as it should.

But when i'm walking forward and then look to the left or right, it suddenly looks like i'm rotating around some point behind me, looks weird and i would really like a solution on that if possible, though my biggest problem is than when i walk forward and look around, i suddenly fall through the terrain.

I've got colliders on and there's not a single problem until i start rotating.

Any solutions?

avatar image
0

Answer by Josh707 · Nov 22, 2012 at 12:24 AM

Kind of late but I think if you make an if statement checking if the value of the rotation is over a certain point, lets say, -180 then set it to 180, which is the same position but just the reversed value. Instead of those values try limiting it in random ranges like 0-360, -180 to 180

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

7 People are following this question.

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

Related Questions

Camera not rotate when following player 1 Answer

How to rotate the player to the direction of the camera 1 Answer

How can I keep a player inside the camera box? [C#] 3 Answers

How to set the player in front of the camera in any rotation 1 Answer

Rotating GameObject Around Player With "Mouse Y" Position 2 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