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 yamslayer · Jun 05, 2015 at 08:28 PM · scripting probleminput

Event from simultaneously pressing button + axis?

Hi all, I'm attempting to create input for combat and could use some help. I need to be able to handle 3 "types" of attack input, ala smash bros - doing in C# but it's really the logic I'm interested in.

1) button press, no axis input 2) button press while tilting analog stick (or holding axis key) 3) button press and analog stick direction press at the same time

Each of these scenarios results in different actions. How would you go about the logic of 3), without it just resulting in the 1) or 2) events firing? Also, how might you create a "buffer" in 3) so that the player's timing in pressing the button and axis direction simultaneously can be a bit off (a bit more forgiving for the player)?

Bonus! How would you allow for case 3) to be chargeable, also ala smash bros? That is, you can initiate the move and then continue to hold the button (but axis no longer matters) to charge the move?

Thanks for any input!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Eno-Khaon · Jun 05, 2015 at 09:25 PM

If it's meant to literally be based on Smash Bros. style, then you need to consider some of the things they specifically handle: For control pad/keyboard input, you would need to double-tap a direction to run, whereas the analog stick input monitors the time from starting to hold a direction until it passes a threshhold to determine whether the player is walking or running.

Based on that threshhold for analog stick control or a secondary timer relative to pressing a direction/key, figure out how long of a delay there should be on the input before the attack is no longer attached to the action.

With this in mind, you would want a few variables available, including time for last directional input, last direction pressed and/or held (could be a Vector2, depending on how much diagonals would be factored in), and a delay value before the combination of direction/attack is invalidated. Once the direction is no longer held, empty the timer (-1 is often a convenient, "safe" value to fall back on). Or, if a new direction is initialized quickly, reset the timer instead (in the case of the Vector2 basis for direction, test whether the Dot product of the previous and current direction held on the stick is less than 0, basically. If so, the player mashed the opposite direction for a quick turn-around attack).

If it's intended for either attack or direction to come first when pairing them together, then it becomes a messy decision on whether there should be a delay before the attack input is fully counted (which is generally a bad idea for fighting games).

Edit: As for charging up such an attack, it might be prudent to keep tabs on whether buttons are actively being held or not (i.e. OnKeyDown("SomeKey") sets a bool to true, OnKeyUp("SomeKey") sets it to false). Then, when the condition is met for the strong attack, instead of simply executing the attack immediately, wait until the charge time has elapsed or the attackKeyDown boolean is false, whichever comes first.

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 yamslayer · Jun 08, 2015 at 05:58 AM

Thanks, there's good ideas in there, and I ended up using most of those ideas, and it simplified the code down into a small nested if series. Here's what I've ended up with so far, in case anyone else is looking to solve something similar:

 if (attack){
             // start counting button hold time
             attackHoldTimer = 0f;
 
             if( h != 0 || v != 0 ){
                 if( axisInputTimer <= axisInputWindow ){
                     smashAttack();
                 } else {
                     tiltAttack();
                 }
             } else {
                 neutralAttack();
             }
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

"Mouse Scrollwheel" on xbox 360controller 2 Answers

Press button once to enter vehicle and once again to exit 1 Answer

How to rotate with mouse scroll wheel and new input system? 1 Answer

Gravity Switch Touch 1 Answer

Use Standard Assets Mobile Input Script 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