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 /
  • Help Room /
avatar image
0
Question by timmyiscool8 · Dec 18, 2018 at 04:50 PM · mousecontrollerprogramming

USB Controller Axis overriding mouse!

Basically, I have this script that sets up the first person character's camera. A while ago I created it to take a Vector3 of the mouse x and y and rotate the camera based off of those numbers. It worked great. So, now that I am adding USB controller support, I just redo the scripts, but instead Mouse X and Y, I do axis 3 and 4... It works, except now, the camera gets rotated by the controller, but the mouse is no longer able to rotate it. I think it has something to do with telling the script to assign the rotation to the camera from the controller right after the mouse, so it just chooses the one in front. THE ISSUE HAPPENS AROUND 95 Here is the script:

 using UnityEngine;
 
 [RequireComponent(typeof(Animator))]
 [RequireComponent(typeof(ConfigurableJoint))]
 [RequireComponent(typeof(PlayerMotor))]
 public class PlayerController : MonoBehaviour
 {
 
     [SerializeField]
     private float speed = 5f;
     [SerializeField]
     private float lookSensitivity = 3f;
 
     [SerializeField]
     private float thrusterForce = 1000f;
 
     [SerializeField]
     private float thrusterFuelBurnSpeed = 1f;
     [SerializeField]
     private float thrusterFuelRegenSpeed = 0.3f;
     private float thrusterFuelAmount = 1f;
 
     private float maxSpeed = 10f;
     private float minSpeed = 5f;
 
     public float GetThrusterFuelAmount()
     {
         return thrusterFuelAmount;
     }
 
     [SerializeField]
     private LayerMask environmentMask;
 
     [Header("Spring settings:")]
     [SerializeField]
     private float jointSpring = 20f;
     [SerializeField]
     private float jointMaxForce = 40f;
 
     // Component caching
     private PlayerMotor motor;
     private ConfigurableJoint joint;
     private Animator animator;
 
     void Start()
     {
         motor = GetComponent<PlayerMotor>();
         joint = GetComponent<ConfigurableJoint>();
         animator = GetComponent<Animator>();
 
         SetJointSettings(jointSpring);
 
         speed = minSpeed;
     }
 
     void Update()
     {
         if (PauseMenu.IsOn)
         {
             if (Cursor.lockState != CursorLockMode.None)
                 Cursor.lockState = CursorLockMode.None;
 
             motor.Move(Vector3.zero);
             motor.Rotate(Vector3.zero);
             motor.RotateCamera(0f);
 
             return;
         }
 
         if (Cursor.lockState != CursorLockMode.Locked)
         {
             Cursor.lockState = CursorLockMode.Locked;
         }
 
         if (Input.GetButtonDown("Sprint"))
         {
             speed = maxSpeed;
         } if (Input.GetButtonUp("Sprint"))
         {
             speed = minSpeed;
         }
 
         //Setting target position for spring
         //This makes the physics act right when it comes to
         //applying gravity when flying over objects
         RaycastHit _hit;
         if (Physics.Raycast(transform.position, Vector3.down, out _hit, 100f, environmentMask))
         {
             joint.targetPosition = new Vector3(0f, -_hit.point.y, 0f);
         }
         else
         {
             joint.targetPosition = new Vector3(0f, 0f, 0f);
         }
 
         //Calculate movement velocity as a 3D vector
         float _xMov = Input.GetAxis("Horizontal");
         float _zMov = Input.GetAxis("Vertical");
 
         Vector3 _movHorizontal = transform.right * _xMov;
         Vector3 _movVertical = transform.forward * _zMov;
 
         // Final movement vector
         Vector3 _velocity = (_movHorizontal + _movVertical) * speed;
 
         // Animate movement
         animator.SetFloat("ForwardVelocity", _zMov);
 
         //Apply movement
         motor.Move(_velocity);
 
         //Calculate rotation as a 3D vector (turning around)
         float _yRot = Input.GetAxisRaw("Mouse X");
 
         Vector3 _rotation = new Vector3(0f, _yRot, 0f) * lookSensitivity;
 
         //Apply rotation
         
         //Calculate camera rotation as a 3D vector (turning around)
         float _xRot = Input.GetAxisRaw("Mouse Y");
 
         float _cameraRotationX = _xRot * lookSensitivity;
 
         // END OF MOUSE CONTROLS, NOW FOR CONTROLLER
         float _ContyRot = Input.GetAxisRaw("Axis 3");
 
         Vector3 _Controtation = new Vector3(0f, _ContyRot, 0f) * lookSensitivity;
 
         //Calculate camera rotation as a 3D vector (turning around)
         float _ContxRot = Input.GetAxisRaw("Axis 4");
 
         float _cameraContRotationX = _ContxRot * lookSensitivity;
                
         //Apply camera rotation
         motor.RotateCamera(_cameraRotationX);
         motor.Rotate(_rotation);
         //Apply camera rotation from controller.
         motor.RotateCamera(_cameraContRotationX);
         motor.Rotate(_Controtation);
 
         // Calculate the thrusterforce based on player input
         Vector3 _thrusterForce = Vector3.zero;
         if (Input.GetButton("Jump") && thrusterFuelAmount > 0f)
         {
             thrusterFuelAmount -= thrusterFuelBurnSpeed * Time.deltaTime;
 
             if (thrusterFuelAmount >= 0.01f)
             {
                 _thrusterForce = Vector3.up * thrusterForce;
                 SetJointSettings(0f);
             }
         }
         else
         {
             thrusterFuelAmount += thrusterFuelRegenSpeed * Time.deltaTime;
             SetJointSettings(jointSpring);
         }
 
         thrusterFuelAmount = Mathf.Clamp(thrusterFuelAmount, 0f, 1f);
 
         // Apply the thruster force
         motor.ApplyThruster(_thrusterForce);
 
     }
 
     private void SetJointSettings(float _jointSpring)
     {
         joint.yDrive = new JointDrive
         {
             positionSpring = _jointSpring,
             maximumForce = jointMaxForce
         };
     }
 
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by timmyiscool8 · Dec 18, 2018 at 04:51 PM

It starts at area 95 and ends at area 140

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

178 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

Related Questions

How to rotate Z axis through Right Joystick (For 2D Topdown Game) 0 Answers

Trying to get camera to follow mouse, and player movement to be relative to camera angle? 0 Answers

How would do I play a walking animation when i move my joystick? 0 Answers

How to make my flashlight move with the mouse movement? 0 Answers

Quaternion.Slerp rotating only 90 degrees. 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