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
0
Question by DavidJCole · May 02, 2020 at 07:53 AM · cameracamera-movementcamera rotate

How do I make a camera add torque on two different axis?

I have a player attached to an empty object, as well as a camera attached to an empty object. (labeled tag 1 and tag 2, tag 1 being attached to the player, tag 2 being attached to the camera.) In this specific movement system, tag 1 rotates to move tag 2 (and the camera) around the player, while tag 2 rotates up and down to make the camera look up and down. (I have also put a barrier in place so the camera doesn't go too high or low) The problem is, I cannot move the camera around the player when I have both functions activated, although when either of them are activated individually they work fine. My first thought was to split them up into separate scripts, but that would be clutter. Please excuse the variable names lmao.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class cameraMovement : MonoBehaviour
 {
     public Transform cam;
     public Rigidbody tag1rb;
     public Transform tag1;
     public Rigidbody tag2rb;
     public Transform tag2;
     public Transform littlespheredude;
 
     public Vector3 offset;
     
     public float xSensitivity;
     public float ySensitivity;
 
     private void FixedUpdate()
     {
         Cursor.lockState = CursorLockMode.Locked;
 
         cam.position = tag2.position;
         cam.rotation = tag2.rotation;
         tag1.position = littlespheredude.position;
 
         Debug.Log("Mouse = " + Input.GetAxis("Mouse X"));
 
         xSensitivity = Input.GetAxis("Mouse X");
         ySensitivity = -Input.GetAxis("Mouse Y") * 10;
 
         LookHori();
         LookVert();
     }
 
     void LookHori()
     {
         if (Input.GetAxis("Mouse X") > 0)
         {
             //Debug.Log("Mouse Right");
             tag1rb.angularDrag = 0;
             tag1rb.AddTorque(0, xSensitivity, 0);
         }
         else if (Input.GetAxis("Mouse X") < 0)
         {
             //Debug.Log("Mouse Left");
             tag1rb.angularDrag = 0;
             tag1rb.AddTorque(0, xSensitivity, 0);
         }
         else
         {
             tag1rb.angularDrag = 20;
         }
     }
 
     void LookVert()
     {
         if (Input.GetAxis("Mouse Y") > 0)
         {
             //Debug.Log("Mouse up");
             tag1rb.angularDrag = 0;
             tag2rb.AddTorque(ySensitivity, 0, 0);
             if (tag2.rotation.x <= -.2)
             {
                 tag2rb.freezeRotation = true;
             }
             else
             {
                 tag2rb.freezeRotation = false;
             }
         }
         else if (Input.GetAxis("Mouse Y") < 0)
         {
             //Debug.Log("Mouse down");
             tag1rb.angularDrag = 0;
             tag2rb.AddTorque(ySensitivity, 0, 0);
             if (tag2.rotation.x >= .2)
             {
                 tag2rb.freezeRotation = true;
             }
             else
             {
                 tag2rb.freezeRotation = false;
             }
         }
         else
         {
             tag2rb.angularDrag = 20;
         }
     }
 
 }
 
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

194 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

Related Questions

Camera gets stuck when cursor is locked 0 Answers

Why is my camera not snapping 90 degrees? 0 Answers

change objects Axis to match cameras rotation 0 Answers

URGENT Cinemachine virtual camera while falling 1 Answer

Allow both turning of the mouse and turning of the player to keep the camera pointing towards the player 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