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 RyanAchtenSoma · Oct 14, 2015 at 11:06 PM · javascriptfirst-person-controllernamespacerotating

Preventing the first person controller from rotating

Hi Unity Community

I am trying to prevent the First Person character from rotating via mouse click however I cannot seem to access the appropriate field; how is this supposed to be achieved? I’m currently thinking the best approach might be change the x/y mouse sensitivity variables (held in the MouseLook class) to 0 however I can’t seem to do this.

(FYI I am programming in uJs.)

I have tried accessing the UnityStandardAssets.Characters.FirstPerson namespace but to no avail (returns ‘not found, maybe you forgot to add an assembly namespace’ - what is the appropriate namespace I require?)

I have also tried accessing the field directly (as per existing posts on the issue) via .GetComponent(MouseLook) also to no avail.

What is the best method of achieving this?

Current Code:

 import UnityStandardAssets.Characters.FirstPerson;
 var browseMenu : GameObject;
 var browseMenuButton : GameObject;
 var menuActive : boolean;
 private var menuMode : boolean;
 
 
 
 
 function Start () {
     
     var fpcScript = gameObject.GetComponent(MouseLook);
 }
 
 
 function setMode()
 {
     if(!menuMode) //if not in menuMode turn it on
     {
         browseMenu.SetActive(true);
         browseMenuButton.SetActive(true);
         MouseLook.XSensitivity = 0;
     
     }
 }

Field To Access: alt text

screen-shot-2015-10-15-at-115930-am.jpg (30.5 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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by vdwtanner · Dec 22, 2015 at 08:41 PM

I just modified the code for the first person character to include a couple of public methods that set the x/y sensitivity that I am able to access via broadcast messages. It's not as nice as I'd like, but it certainly does the job.

         public void pauseMouseLook(){
             m_MouseLook.XSensitivity = 0F;
             m_MouseLook.YSensitivity = 0F;
         }
 
         public void resumeMouseLook(){
             m_MouseLook.XSensitivity=m_MouseLook.oldXS;
             m_MouseLook.YSensitivity=m_MouseLook.oldYS;
         }

Access with: BroadcastMessage("pauseMouseLook"); or BroadcastMessage("resumeMouseLook");

Unfortunately I can't help with why it doesn't like the namespace since I mainly work in C# when using Unity.

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

30 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

Related Questions

Namespace declaration for UnityScript or Unity Javascript 0 Answers

CS0246: The type or namespace name `targetPosition' could not be found. Are you missing a using directive or an assembly reference? 1 Answer

Disable First Person Controller upon death. 4 Answers

Help me Convert JS to C# 2 Answers

Instantiating Particle System and Editing Base Settings 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