Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 Jun 22 - 14 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 ZorinAndreyko · Apr 21 at 09:32 AM · camera-movement

Why my camera Start to change position???

https://youtu.be/jknmfhhjsc0

using UnityEngine;

 public class ThirdPersonMovement : MonoBehaviour
 
 {
 
 public GameObject cam;
 
 public Rigidbody rb;
 
 
 
 bool isSprinting = false;
 
 public float sprintingMultiplieer;
 
 public float speed = 0.1f;
 
 public float Xsens = 2;
 
 public float Ysens = 2;
 
 public float Minimumx = -60f;
 
 public float MaximumX = 4.05f;
 
 float x;
 
 float z;
 
 
 
 Quaternion camerarot;
 
 Quaternion characterRot;
 
 void Start()//All Start
 
 {//////////////////////
 
 rb = this.GetComponent<Rigidbody>();
 
 camerarot = cam.transform.localRotation;
 
 characterRot = this.transform.localRotation;
 
 Cursor.lockState = CursorLockMode.Locked;
 
 Cursor.visible = false;
 
 
 
 }
 
 private void Update()
 
 {
 
 if (Input.GetKey(KeyCode.LeftShift))
 
 {
 
 isSprinting = true;
 
 }
 
 else
 
 {
 
 isSprinting = false;
 
 }
 
 }
 
 private void FixedUpdate()//all Controls
 
 {///////////////////////////////////////
 
 float yRot = Input.GetAxis("Mouse X");
 
 float xRot = Input.GetAxis("Mouse Y");
 
 
 
 
 
 camerarot *= Quaternion.Euler(-xRot * Xsens, 0, 0);
 
 characterRot *= Quaternion.Euler(0, yRot * Ysens, 0);
 
 
 
 this.transform.localRotation = characterRot;
 
 cam.transform.localRotation = camerarot;
 
 camerarot = ClampRotationAround_X_Axes(camerarot);
 
 camerarot.z = 0;
 
 x = Input.GetAxis("Horizontal") * speed;
 
 z = Input.GetAxis("Vertical") * speed;
 
 if (isSprinting == true)
 
 {
 
 x *= sprintingMultiplieer;
 
 z *= sprintingMultiplieer;
 
 }
 
 transform.position += cam.transform.forward * z + cam.transform.right * x; //new Vector3(x * speed, 0, z * speed);
 
 }
 
 //private void Update()
 
 //{
 
 // camerarot = ClampRotationAround_X_Axes(camerarot);
 
 
 
 //}
 
 Quaternion ClampRotationAround_X_Axes(Quaternion q)//nullQuaternion
 
 {//////////////////////////////////////////////////////////////////
 
 q.x /= q.w;
 
 q.z /= q.w;
 
 q.y /= q.w;
 
 q.w = 1.0f;
 
 
 
 float AngelX = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.x);
 
 AngelX = Mathf.Clamp(AngelX, Minimumx, MaximumX);
 
 q.x = Mathf.Tan(0.5f * Mathf.Deg2Rad * AngelX);
 
 return q;
 
 }
 
 }


alt textalt text

screenshot-2022-04-19-at-142601.png (431.6 kB)
screenshot-2022-04-19-at-141440.png (450.3 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

141 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 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

Control camera rotation by induvidual axises through Vector3s (for a fixed camera system) 0 Answers

3rd Person Orbit Camera in LOCAL Space 0 Answers

Is it possible to reuse input's acceleration in custom script? 2 Answers

Help with a 2d camera Controller 1 Answer

Why is Camera turning different than Player with same code in different scripts? 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