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 mzaidan1996 · Jul 24, 2020 at 11:06 AM · cameracamera-movementcamera rotatecamera-lookcamera movement

My camera is not linking with my movement

Im currently making a FPS anM i have already created my movement and look controls, but when i look in a certain direction and I press W, it moves me to another direction, I think my vector3 is linked to the world instead of my character, does anyone know how to solve this issue, this is my movement script:

  private void Awake()
  {
      //This is to get the information of our rigidbody and store it in the rb variable.
      rb = GetComponent<Rigidbody>();
  }
  private void Start()
  {
  }
  private void Update()
  {
      MovementInputs();
      Jumping();
  }
  private void FixedUpdate()
  {
      Movement();
  }
  private void MovementInputs()
  {
      //Those are for the inputs for the movement. This information is stored within the x and z variables.
      x = Input.GetAxisRaw("Horizontal");
      z = Input.GetAxisRaw("Vertical");
  }
  private void Movement()
  {
      //This is to create the movement and change our rigidbody's velocity based on the x and z which are multiplied by the walk speed.
      Vector3 movement = rb.velocity = new Vector3(x * walkSpeed, rb.velocity.y, z * walkSpeed);
      
  }
  private void Jumping()
  {
      //This is to get the input which is space and if it is pressed.
      if (Input.GetKeyDown(KeyCode.Space))
      {
          //If the space button is pressed, the velocity will change, the x and z will stay the same but the y will change based on the jump force applied.
          rb.velocity = new Vector3(x, jumpForce, z);
      }
  }

} and this is my look controls script: private void Start() { playerBody = transform.parent.gameObject; //This is to lock and make the cursor invisible while playing the game. Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } private void Update() { CameraRotation(); } private void FixedUpdate() {

  }
  private void CameraRotation()
  {
      //This is to get the values of the axis from the Mouse X and Mouse Y which are shown in unity.
      Vector2 inputValues = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
      //This is for the up, down, left and right movement and to scale down the movement of the camera by smoothing and the sensitivity.
      inputValues = Vector2.Scale(inputValues, new Vector2(mouseSensitivity * mouseSmoothing, mouseSensitivity * mouseSmoothing));
      //This is to let the camera movement exist and to create a smoothing effect so the camera doesnt suddenly stop.
      smoothedVelocity.x = Mathf.Lerp(smoothedVelocity.x, inputValues.x, 1f / mouseSmoothing);
      smoothedVelocity.y = Mathf.Lerp(smoothedVelocity.y, inputValues.y, 1f / mouseSmoothing);
      currentlookingPos += smoothedVelocity;
      //Everything written in this bracket above is made for the calculations. Everything down now is for the actual movement.
      //wtf are quaterions?????
      transform.localRotation = Quaternion.AngleAxis(-currentlookingPos.y, Vector3.right);
      playerBody.transform.localRotation = Quaternion.AngleAxis(currentlookingPos.x, playerBody.transform.up);
      //This is to stop the full camera rotation infinite thingy, idk.
      currentlookingPos.y = Mathf.Clamp(currentlookingPos.y, -80f, 80f);
  }

}

Thanks and take care everyone.

Comment
Add comment · Show 1
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 Llama_w_2Ls · Jul 25, 2020 at 05:47 PM 0
Share

check if your player body is actually rotating when you look around

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

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

Automatic Camera Rotation in the 3D Game Kit 0 Answers

How to pan the camera depending on the zoom 1 Answer

Cinemachine input axis camera movement,cinemachine input axis control with script 1 Answer

How to allow camera to complete an upside down rotation while using LookAt() 0 Answers

Unity - Dancing Ball World camera following and rotating system 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