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 prototyped · Mar 21, 2019 at 08:07 PM · input2d gamecontrols2d-gameplay

arcade stick input commands implementation

So Im trying to find a way to make quarter circle inputs like in 2-d fighting games but i can't find any documentation or tutorials to help me, i know im going to need to do input buffering but im running out of leads.

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
0

Answer by WarmedxMints · Mar 21, 2019 at 10:11 PM

I've never needed to do anything like this but it got me interested so I had a think. What I came up with was to split the directions into regions, that way if the player is using a gamepad and not a stick, it won't matter. Then when the region changes, compare it again a preset sequence.
This is what I came up with;

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public enum StickRegion
 {
     Centre,
     Top,
     TopLeft,
     TopRight,
     MiddleLeft,
     MiddleRight,
     BottomLeft,
     BottomRight,
     Bottom
 }
 
 public class InputRegion : MonoBehaviour
 {
     public List<Sequence> sequences = new List<Sequence>();
 
     private StickRegion _currentRegion;
     private StickRegion _lastRegion;
 
     public void Update()
     {
         var stickpos = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
 
         _currentRegion = GetStickRegion(stickpos);
 
         if(_currentRegion != _lastRegion)
         {
             Debug.Log(_currentRegion);
             _lastRegion = _currentRegion;
 
             CheckSequences(_currentRegion);
         }
     }
 
     private void CheckSequences(StickRegion region)
     {
         for(var i = 0; i < sequences.Count; i++)
         {
             //If the new region matechs the next region in the sequence
             if(region == sequences[i].sequence[sequences[i].currentIndex])
             {
                 //Advanve our index by one
                 sequences[i].currentIndex++;
 
                 //Count has reached the end of the sequence so all inputs matched
                 if(sequences[i].currentIndex > sequences[i].sequence.Count - 1)
                 {
                     //Do something when that combo has been performed
                     Debug.Log("Combo " + i.ToString() + " Success");
                     //Reset the index back to 0 ready for it to fire again
                     sequences[i].currentIndex = 0;
                 }
                 continue;
             }
             //The inputs did not match the sequence somewhere so we reset it back to the start
             sequences[i].currentIndex = 0;
         }
     }
 
     public StickRegion GetStickRegion(Vector2 stickPos)
     {
         if (Mathf.Abs(stickPos.x) < 0.3f && Mathf.Abs(stickPos.y) < 0.3f)
             return StickRegion.Centre;
 
         if(Mathf.Abs(stickPos.x) < 0.3f)
         {
             if (stickPos.y > 0.3f)
                 return StickRegion.Top;
             if (stickPos.y < -0.3f)
                 return StickRegion.Bottom;
         }
 
         if(stickPos.x > 0.3f)
         {
             if (Mathf.Abs(stickPos.y) < 0.3f)
                 return StickRegion.MiddleRight;
 
             if (stickPos.y > 0.3f)
                 return StickRegion.TopRight;
             if (stickPos.y < -0.3f)
                 return StickRegion.BottomRight;  
         }
 
         if(stickPos.x < -0.3f)
         {
             if (Mathf.Abs(stickPos.y) < 0.3f)
                 return StickRegion.MiddleLeft;
 
             if (stickPos.y > 0.3f)
                 return StickRegion.TopLeft;
             if (stickPos.y < -0.3f)
                 return StickRegion.BottomLeft;
         }
 
         return StickRegion.Centre;
     }
 }
 
 [Serializable]
 public class Sequence
 {
     public List<StickRegion> sequence;
     public int currentIndex;
 }
 

Now, of course, you would want to expand on the Sequence class and likely record the time of the last input so you can check it has not taken too long to perform each move. I would also probably make it a scriptable object with a virtual method which each Sequence can inherit from and then you can call that method to decide what to do when the combo has been performed.

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

140 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 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 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 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 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

how can I assign and use different controller schemes for a single keyboard? 0 Answers

How to Attack using Animation and Input 0 Answers

Make objects invisable when they are passing through 2 Answers

How do i make my 2d character move one step at a time? 1 Answer

Creating a 3D world for a 2D game: better to do it all in 2D or 3D? 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