• 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 mechanicarts · Feb 01, 2013 at 10:28 PM · collisioncombogesture

Combo system based on collision

I have the following code. What it is supposed to do is print the identifier of each collider, and if the Array that contains the colliders of the 2 last seconds equals to a predefined combo array, print something else. It doesn't work. It prints EACH collider as expected, but never the combo. Here is my code.

 var COMBO:Array;
 static var MoveLeftHandCombo:Array=["A","B"];
 static var MoveRightHandCombo:Array=["C","D"];
 
 public var startime:float=0;
 public var endtime:float=2;
 private var thistime:float=0;
 
 function Awake()
 {
     thistime=startime;
     GEST_A=GameObject.Find("GEST_A");
     GEST_B=GameObject.Find("GEST_B");
     GEST_C=GameObject.Find("GEST_C");
     GEST_D=GameObject.Find("GEST_D");
 
 function Update()
 {
     if (thistime<endtime)
     {
         thistime+=Time.deltaTime;
     
     }
     else
     {
         COMBO=[];
     }
     if (COMBO==MoveLeftHandCombo)
     {
         Debug.Log("MoveLeftHandCombo");
     }
     else if (COMBO==MoveRightHandCombo)
     {
         Debug.Log("MoveRightHandCombo");
     }
 }
 
 function OnTriggerEnter(coll:Collider)
 {
     if (coll.gameObject==GEST_A)
     {
         COMBO.push("A");
         Debug.Log(COMBO);
     }
     if (coll.gameObject==GEST_B)
     {
         COMBO.push("B");
         Debug.Log(COMBO);
     }
     if (coll.gameObject==GEST_C)
     {
         COMBO.push("C");
         Debug.Log(COMBO);
     }
     if (coll.gameObject==GEST_D)
     {
         COMBO.push("D");
         Debug.Log(COMBO);
     }
 
 
 }
Comment
Add comment · Show 1
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 iwaldrop · Feb 01, 2013 at 11:55 PM 0
Share

Is CO$$anonymous$$BO being set to [] before the 2 second window? Experiment with getting the combo system to work with no time in order to rule out any logic problems. When you can hit both objects and get the correct combo message to fire then you should implement a timer on it.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Vonni · Feb 02, 2013 at 12:10 AM

Didn't know COMBO=[] worked :S Doesn't look like it would!

Also, im not even sure comparing two identical arrays like : if(array1 == array2) would even work. Because i don't think it checks the content ( i could be wrong here ).

Try debugging and remove timer.

I would also suggest switching from arrays to a string

 //Maybe store this in an string[] builtin array ???
 var SuperRightHandCombo : string = "abcd";
 var NotSoGreatKickToTheFaceCombo : string = "bcbc";
 
 //and then simply
 
 var currentCombo : string;
 if (coll.gameObject==GEST_A)
 {
     currentCombo += "a" // Or b, c, d, e, f ,g ,w
 }

EDIT: TESTED Array comparison

 var array1 : Array = [4,4,4,4];
 var array2 : Array = [4,4,4,4];
 function Start () {
 if(array1 == array2)
     print("They are alike!");
 else
     print("Not alike");
 }

And it does NOT work.

EDIT 2: Regarding time and combo checking

Instead of declaring a time a combo needs to be executes within. Instead declare a time for which each input (a , b or c ... etc) has to be within oneanother.

 import System.Collections.Generic;
 
 class CombatInput {
    var atTime : float;
    var move : string;
 }
 
 var combatInput : List.< CombatInput > = new List.< CombatInput >();
 var comboSpeed : float = 0.5;

 var superAwesomeSpinAttack : string = "abcd";

 if (coll.gameObject==GEST_A)
 {
     // Maybe make a function out of this these if statements so you dont have to type em over and over again for each input check
     if(combatInput.Count != 0){ // checks if list is empty
        // Checks the LATEST variable in your LIST and sees if it was more than comboSpeed (in time) ago.
        if(combatInput[combatInput.Count].atTime + comboSpeed < Time.time){
            combatInput.Clear();
        }
     }
     combatInput.Add(CombatInput(Time.time, "a");
     if(combatInput.Count == 4){
         var currentCombo : string = "";
         for(var i : int; i < combatInput.Count; i++){
            currentCombo += combatInput[i].move;
         }
         if(currentCombo == superAwesomeSpinAttack){
             // Do combo move somehow
         }
     }
 
 }
Comment
Add comment · Show 5 · 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 mechanicarts · Feb 02, 2013 at 12:58 AM 0
Share

This works without time! But I need time, so that it can clear if combo is not done in 2 secs. It doesn't work with my current setup.

avatar image iwaldrop · Feb 02, 2013 at 01:29 AM 0
Share

Record the time of the last hit and add your interval to it. If that value becomes greater or equal to the current time then clear you list.

avatar image Vonni · Feb 02, 2013 at 12:26 PM 0
Share

Upvote maybe if it worked for you. As far as time goes. You should be able to figure that out yourself.

avatar image mechanicarts · Feb 02, 2013 at 01:35 PM 0
Share

Regarding iwaldrop's answer, how do you record the time of last hit?

avatar image Vonni · Feb 02, 2013 at 02:18 PM 0
Share

I think you need to think a bit more about how that combo system will work. Because it seems to me like you want it to start some timer on the first hit, and then if at any point you do a sequence after that and within the time limit, the combo would execute. But there might be a problem with that. SAY, someone wants to do the combo = abcd. But does a simple jab with the "b" to hit the target. THAT would start the timer... and whatever is done after that will be babcd, and simply would not start the combo. The system needs to be more complex. EXA$$anonymous$$PLE: you hit bbbabcdbaabc over 5 seconds. That might make the CURRENT combo: bbbab and cdba amd abc... none which make you do any combo. You need a system that tracks all the input (a,b,c etc.. d a) and then has some way of checking if a sequence matches the combo AND are all without 2 seconds of oneanother.

UPDATED ANSWER WITH A SOLUTION.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

help with fruit ninja like slice combo 1 Answer

help with scripting combo points 1 Answer

collision combo 1 Answer

add collision to animated object 1 Answer

Terrain collision problem 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