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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by umrkygsz · Nov 27, 2013 at 10:20 PM · mousefirst person controllerlookturningright

How to disable my mouse to turn right

Hello everyone, I need help with coding and I've no idea how to do it. Basically, I don't want my "First Person Controller" (standart assets/character controller) to be able to turn right. Now I understand it works as X and Y but is there any way I can disable for it to turn right, and only turn left (X-wise. I want Y to stay as it is)

I've seen and tried changing "Minimum X, Maximum X" but it doesn't work. It always lets player turn right and left.

Comment
Add comment · Show 3
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 umrkygsz · Nov 27, 2013 at 09:50 PM 0
Share

[AddComponent$$anonymous$$enu("Camera-Control/$$anonymous$$ouse Look")] public class $$anonymous$$ouseLook : $$anonymous$$onoBehaviour {

 public enum RotationAxes { $$anonymous$$ouseXAndY = 0, $$anonymous$$ouseX = 1, $$anonymous$$ouseY = 2 }
 public RotationAxes axes = RotationAxes.$$anonymous$$ouseXAndY;
 public float sensitivityX = 15F;
 public float sensitivityY = 15F;

 public float $$anonymous$$imumX = -360F;
 public float maximumX = 360F;

 public float $$anonymous$$imumY = -60F;
 public float maximumY = 60F;

 float rotationY = 0F;

 void Update ()
 {
     if (axes == RotationAxes.$$anonymous$$ouseXAndY)
     {
         float rotationX = transform.localEulerAngles.y + Input.GetAxis("$$anonymous$$ouse X") * sensitivityX;
         
         rotationY += Input.GetAxis("$$anonymous$$ouse Y") * sensitivityY;
         rotationY = $$anonymous$$athf.Clamp (rotationY, $$anonymous$$imumY, maximumY);
         
         transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
     }
     else if (axes == RotationAxes.$$anonymous$$ouseX)
     {
         transform.Rotate(0, Input.GetAxis("$$anonymous$$ouse X") * sensitivityX, 0);
     }
     else
     {
         rotationY += Input.GetAxis("$$anonymous$$ouse Y") * sensitivityY;
         rotationY = $$anonymous$$athf.Clamp (rotationY, $$anonymous$$imumY, maximumY);
         
         transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
     }
 }
 
 void Start ()
 {
     // $$anonymous$$ake the rigid body not change rotation
     if (rigidbody)
         rigidbody.freezeRotation = true;
 }

}

avatar image tanoshimi · Nov 27, 2013 at 10:21 PM 0
Share

Setting $$anonymous$$imumX and maximumX will have no effect because they're not used in your script anywhere. You need to add a clamp statement to the rotationX in the same way that you've clamped rotationY between $$anonymous$$imumY and maximumY

avatar image umrkygsz · Nov 28, 2013 at 05:09 PM 0
Share

Thank you for your comment, I've edited my code and it's "half-working" right now but still not the result I want. $$anonymous$$ouse doesn't turn right when we don't turn left. But if mouse turns left, we can go right. Till the point in the beginning, where mouse can't turn right. :/

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Nov 27, 2013 at 10:37 PM

You will need to ignore either positive or negative input from the Input.GetAxis(). So change line 27 to either this:

 float inputX = Input.GetAxis("Mouse X");
 if (inputX > 0.0f)
     transform.Rotate(0.0f, inputX * sensitivityX, 0.0f);

or

 float inputX = Input.GetAxis("Mouse X");
 if (inputX < 0.0f)
     transform.Rotate(0.0f, inputX * sensitivityX, 0.0f);
Comment
Add comment · Show 5 · 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 umrkygsz · Nov 28, 2013 at 05:07 PM 0
Share

Hello there! I tried your code but it didn't work. Gives an error with Remote. :(

I've modified my code and it's something like this now:

And the thing is, "it doesn't turn right in the beginning" (which is great) "BUT when we turn left we can turn right". We only can't turn right in the beginning point. So my problem is not solved, people can still turn right. Is there any way we can fix this by something like... No matter when & how much camera turns left, mouse can't turn right? I'm really not good at this and my game depends on this aspect.

 using UnityEngine;
 using System.Collections;
 
 [AddComponent$$anonymous$$enu("Camera-Control/$$anonymous$$ouse Look")]
 public class $$anonymous$$ouseLook : $$anonymous$$onoBehaviour {
     
     public enum RotationAxes { $$anonymous$$ouseXAndY = 0, $$anonymous$$ouseX = 1, $$anonymous$$ouseY = 2 }
     public RotationAxes axes = RotationAxes.$$anonymous$$ouseXAndY;
     public float sensitivityX = 15F;
     public float sensitivityY = 15F;
     
     public float $$anonymous$$imumX = -360F;
     public float maximumX = 0F;
     
     public float $$anonymous$$imumY = -60F;
     public float maximumY = 60F;
     
 
     float rotationY = 0F;
     float rotationX = 0F;
     
     void Update ()
     {
         if (axes == RotationAxes.$$anonymous$$ouseXAndY) {
 
 
                         rotationX += Input.GetAxis ("$$anonymous$$ouse X") * sensitivityX;
                         rotationX = $$anonymous$$athf.Clamp (rotationX, $$anonymous$$imumX, maximumX);
                         rotationY += Input.GetAxis ("$$anonymous$$ouse Y") * sensitivityY;
                         rotationY = $$anonymous$$athf.Clamp (rotationY, $$anonymous$$imumY, maximumY);
 
                         transform.localEulerAngles = new Vector3 (-rotationY, rotationX, -360);
 
                 } else {
                 }
     }
     
     void Start ()
     {
         // $$anonymous$$ake the rigid body not change rotation
         if (rigidbody)
             rigidbody.freezeRotation = true;
     }
 }
avatar image robertbu · Nov 29, 2013 at 02:45 AM 0
Share

I don't why the code I provided would have given you an error. As for your problem, is it an issue with orientation? That is, if you rotate something 180 degrees, left rotation becomes right rotation.

avatar image umrkygsz · Nov 29, 2013 at 09:36 AM 0
Share

Hello! I'm using "$$anonymous$$ouseXandY" since it lets mouse to go on both X and Y planes. (looking up-down and right-left) I've deleted the other $$anonymous$$ouseY and $$anonymous$$ouseX cause when they're ticked in "Inspector" part they only used their plane. (only X or only Y)

About Rotate, error is CS0103: The name 'Rotate' does not exist in the current context.

If you can help me, please do. I will surely give credits too :>

avatar image robertbu · Nov 29, 2013 at 04:01 PM 0
Share

It should have been 'transform.Rotate'. I fixed my code. But I unsure that it will be the solution. As I said, part of left/right turning depends on the frame of reference.

avatar image umrkygsz · Nov 29, 2013 at 04:35 PM 0
Share

And it is working now... I can't thank you enough. I CAN'T THAN$$anonymous$$ YOU ENOUGH!

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

17 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

Related Questions

Look around when holding down mousebutton 1 Answer

Mouse Look Script Help 2 Answers

weapon bob when looking 2 Answers

How to control a weapon through a single mouse movement? 2 Answers

Unity Android Movement Problem 0 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