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 HikerJB · Mar 22, 2013 at 02:58 PM · controllerwalkingsteps

Can I change the FPC so that you have to repeatedly press a key to walk?

I'm making a walkthru game that utilizes a dancemat so that you have to actually "walk" instead of just holding down the "W" key. I have the dancemat emulating the keyboard so I'm good there. I just need a slight tweek so that the FPC keeps moving when the key is rcontinually pressed and released. If the player holds the "W" key down for 1 second OR releases it for 1 second the FPC should stop. I know there is probably a lot of work involved, but, just a point in the right direction would be greatly appreciated. Do I need to modify the FPSInput Controller Script, the Character Motor Script, neither one, or start over from scratch with something new? Thanks

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 Owen-Reynolds · Mar 22, 2013 at 03:15 PM

The GetAxis command uses hidden Axis variables, maintained internally by Unity, from key presses. They magically rise to 1 when held and sink to 0 when released. You can just make your own "Axis" variables the same way. The built-in works something like this:

 if( Input.getKey("right")) { // held down
   if(hAxe<0 && snap==true) hAxe=0; // snap turn 

   hAxe += hSpeed * Time.deltaTime; // speed up when held
   if(hSpeed>1) hSpeed=1; // axises go from -1 to 1
 }
  ..... // same for left (skipping)

 else // no key held -- slow down when not held
   hSpeed = Mathf.MoveTowards(hSpeed, 0, hGravity * Time.deltaTime);

I don't quite understand your "1 second rule," but, say you wanted a key to count for up to one second:

 float rightActiveTime;
 if(Input.GetKeyDown("right")) // press -- mark the time
   rightActiveTime=Time.time+1.0f;

 if(Input.GetKey("right") && Time.time < rightActiveTime)
   // key has been held for less than 1 second
Comment
Add comment · Show 3 · 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 HikerJB · Mar 22, 2013 at 04:23 PM 0
Share

Thank you very much that looks awesome. I need time to fully study and understand it. The 1 second rule was just a random time. If someone stops on the mat they are essentially standing on or pressing the "W" key. That would normally make an FPC move forward, but in the walkthru they are stopped so I can't have any movement. The same goes for if they leave the mat. The key is up and there should be no movement of the FPC. The only thing that makes the FPC move is the constant cycling of the key. Is that what you have so generiously given me?

avatar image Owen-Reynolds · Mar 22, 2013 at 06:28 PM 0
Share

Well, you have the ability to detect "just pressed", "just let go" and "currently held down." You can use that to build whatever you want.

For a "keep clicking to run" you might use the trick where you remember the last time they clicked, and within 1 second means they are running.

avatar image HikerJB · Mar 22, 2013 at 07:13 PM 0
Share

Thanks. I wasnt aware if thise functions. I'll check it out.

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

11 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

Related Questions

Animating CharacterController When Stepping Up 0 Answers

Unity Flash, character jumps when the controller touches a step 0 Answers

My character won't move in C#. 1 Answer

Hi, Could someone tell me why this is reversed? 1 Answer

MMD How to export model and animations to Unity as 3rd person controller? 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