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
1
Question by bayerly · Jul 24, 2012 at 12:28 AM · inputkeysrate

How Can I Fight Button Mashing - Need To Slow Down Input Rate

Hi everyone,

I've got a platform fighting game that I've been doing this week as a sort of mini-jam, and I was wondering how I could delay inputs from the "punch" button. I have a basic trigger on my player that collides with the other player's trigger. When P1 uses GetKeyDown(KeyCode.X) while OnTriggerStay is happening, it causes -5 damage to the other player.

Often it registers twice (so -10 on one punch) and I suspect it's because I've made my timestep very small to help read collisions, thus registering two hits in the small time the player activates the key.

I want to set the punch keys to only register every .1 seconds, or something a bit quicker, so you can't just pound the key and do -50 damage in one second.

Any help would be appreciated!

Pat,Hi everyone,

I've got a platform fighting game that I've been doing this week as a sort of mini-jam, and I was wondering how I could delay inputs from the "punch" button. I have a basic trigger on my player that collides with the other player's trigger. When P1 uses GetKeyDown(KeyCode.X) while OnTriggerStay is happening, it causes -5 damage to the other player.

Often it registers twice (so -10 on one punch) and I suspect it's because I've made my timestep very small to help read collisions, thus registering two hits in the small time the player activates the key.

I want to set the punch keys to only register every .1 seconds, or something a bit quicker, so you can't just pound the key and do -50 damage in one second.

Any help would be appreciated!

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 pheash · Jul 24, 2012 at 09:43 AM

Hi, Instead of checking for GetKeyDown in your Update function check it in another function that gets executed every .1 seconds by using InvokeRepeating:

in your controller script:

 function Update(){
  if(playerIsControllable && !IsInvoking("CheckInputs")){ // if we are not already checking for inputs and the player is controllable (boolean that is true during the fight) we start checking for inputs every .1 seconds
       InvokeRepeating("CheckInputs",0,0.1); //starts imediately to execute CheckInputs() every 0.1 seconds
      }
  if(!playerIsControllable){ // if the player is not controllable (eg during startup) we stop checking for inputs.
   CancelInvoke("CheckInputs");
  }
 }
 
 function CheckInputs(){
  //put all your getKeydown stuff in here.
 }

Let me know if you have any problems with that concept.

Comment
Add comment · Show 2 · 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 bayerly · Jul 24, 2012 at 06:20 PM 0
Share

Thanks pheash: this occurred to me, though your structure works great, would have taken me a bit to figure out how to get it going. I haven't tried it yet, and I'll confirm it works, but thanks a bunch! There's no reason invokeRepeating can't be used many times per scene right? I've got powerup randomization scripts that go off every 10 seconds.

avatar image pheash · Jul 24, 2012 at 08:46 PM 0
Share

I think ideally you only invoke a certain function once. you can use if(!IsInvoking("function")) to check whether it isnt actually already invoking. but invokerepeating different functions shouldnt be a problem

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotate an object with angle limit 1 Answer

C# inputString mouse Keys? 1 Answer

How to set Input Buttons 2 Answers

add button like escape or shift 1 Answer

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 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