Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 HamzaNa113 · Mar 02, 2018 at 12:47 PM · quaternionz axis

How to freeze the z axis while rotating

I'm trying to make a third person camera but when rotating the z axis it makes it look weird and i don't know how to make it not rotate the z axis here's my code using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class CameraController : MonoBehaviour
 {
 
     private GameObject player;
     private GameObject cam;
 
     public float senstivity;
     public float smoothing;
 
     // Use this for initialization
     void Start()
     {
         cam = GameObject.FindGameObjectWithTag("MainCamera");
         player = GameObject.FindGameObjectWithTag("Player");
     }
 
     // Update is called once per frame
     void Update()
     {
         if (player == null) return;
         transform.position = new Vector3(player.transform.position.x, player.transform.position.y + 4, player.transform.position.z);
 
         var mouse = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
         var v = new Vector3(-mouse.y, mouse.x, 0) * senstivity * (1 / smoothing);
         transform.localRotation *= Quaternion.Euler(v.x, v.y, 0);
     }
 }

the camera is a child of an gameobject called camera controller which stays on top of the player (because i want the camera to rotate around a point on top of the player)

Comment
Add comment · Show 2
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 Harinezumi · Mar 02, 2018 at 01:19 PM 0
Share

Have you tried using transform.Rotate() (first version) ins$$anonymous$$d of directly multiplying with a rotation? I know it doesn't make sense, but Transform.Rotate() seems to work better.

avatar image HamzaNa113 · Mar 02, 2018 at 01:26 PM 0
Share

i tried that first and it didnt work

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by rugvedkhandekar · Mar 25, 2018 at 05:56 PM

Actually as much as I understood reading your question @HamzaNa113, I am not sure you want to freeze the Z axis rotation of the player Camera or a player or a rigidbody. Well, if its a rigid body, you can check the freeze rotation under constraints in the rigid body menu in the inspector.alt text

And I dont know for sure, but you can experiment by applying rigidbody to the camera and enabling the suitable constraints. I hope my answer helped you.


capture.jpg (22.5 kB)
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 NoMoneys · Mar 25, 2018 at 06:25 PM

Try changing the order of the variables you're putting into Quaternion.Euler(), that should do it.

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

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

FPS camera is repositioning on both the X and Y axis, I only want the camera to slightly tilt (Z axis)...TIA! 2 Answers

Lock Rotation of Object between 2 points, which is looking at the direction the mouse is pointing 0 Answers

Transform Z axis rotation from center of screen toward mouse cursor with Quaternion.LookRotation for a top down game. 2 Answers

How to do relativte offset rotation 0 Answers

Get my head around Unity Rotations 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