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 Klown · Aug 02, 2013 at 07:33 PM · movementfreezetoggleitemfreezeposition

Stop player from moving with WASD while using mouse still.

I want to freeze the player movement with the WASD keys and be able to still use the mouse to look around. I'm essentially opening an item in-game and want this action to freeze the players movement so that the player can look at the item and move the view around.

This is the code I'm using to start the map with the item hidden and pushing "m" will bring up the item.

 using UnityEngine;
 using System.Collections;
 
 public class mapToggle : MonoBehaviour {
  
     // Use this for initialization
  
    void Start () {
         renderer.enabled=false;
         
     }
  
     // Update is called once per frame
     void Update () {
     if(Input.GetKeyDown(KeyCode.M))
        {
             // toggle visibility:
         renderer.enabled = !renderer.enabled;
         }
     }
 }
Comment
Add comment · Show 2
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 EHogger · Aug 02, 2013 at 08:10 PM 0
Share

What script are you using to move the player?

avatar image chronicfail · Aug 02, 2013 at 08:25 PM 0
Share

If you are using the standard assets Character$$anonymous$$otor there is a canControl variable, and when that is set to false WASD movement is disabled, but the seperate mouse look script is unaffected.

put a variable at the top public Character$$anonymous$$otor char$$anonymous$$ot;

assign it in the editter, and in the update section under "toggle visibility" put

 char$$anonymous$$ot.canControl=false;

then, add an "else" section to the if statement containing char$$anonymous$$ot.canControl=true;

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Klown · Aug 07, 2013 at 06:53 PM

This is the working code, with the help and use of some of Chronicfail's code it's working now.

 using UnityEngine;
 using System.Collections;
  
 public class mapToggle : MonoBehaviour {
 public CharacterMotor charMot;
  
     // Use this for initialization
  
    void Start () {
        renderer.enabled=false;
  
     }
  
     // Update is called once per frame
     void Update () {
     if(Input.GetKeyDown(KeyCode.M))
        {
          // toggle visibility:
         renderer.enabled = !renderer.enabled;
        charMot.canControl = !renderer.enabled;   
        }
     }
 }
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
avatar image
0

Answer by WizzDE · Aug 02, 2013 at 09:07 PM

I don't know how you're moving script works but here is a really simple way to do this: You create a public variable in your moving script which needs to be a boolean. Call it something like "canMove". Then you set an if around your movinf part. if (canMove){ //code for moving around } Then all you need to do is change the canMove variable to false whenever you dont want to be able to move: If (Input.GetKeyDown (KeyCode.M)){ GameObject.Find ("YourPlayer").GetComponent (nameOfYourMovingScript).canMove = false; } Hope I helped

Wizz

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

18 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

Related Questions

How to make ball sticky 1 Answer

,Storing Vector3 arrays in another array? 1 Answer

Freeze Character control on axis 0 Answers

How to prevent movement in a specific direction only? -1 Answers

Mouse Look Freeze on Pause? 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