1 (edited by mojao 2014-09-04 10:10:45)

Topic: Tips for multi character

Hello. I was tried to beat em up opponent.
and it is  result.

[media]https://www.youtube.com/watch?v=Ds9EDLJ … e=youtu.be[/media]

it looks like success. But, this test is not perfect.it has a problem.
And there is another big problem.
After test,I was away from coding for some reasons.
Then, I forget problem of this test and I forget where I edit in source code.
So, I will show where and how to edit as far as i canremember.
My method is very very  Dirty.And i am japanese, so my english is dirty.
But I hope this topic help someone,and someone make beauty and good Method.

1.Make Enemy Handler

It is completry my made code, so i past my code.


using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class EnemyList : MonoBehaviour {
    public List<int> IdList = new List<int>();
    public Dictionary<int,PhysicsScript> totalopPhysicsScript = new  Dictionary<int,PhysicsScript>();
    public Dictionary<int,ControlsScript> totalopControlsScript = new Dictionary<int,ControlsScript>();
    public Dictionary<int,HitBoxesScript> totalopHitBoxesScript = new Dictionary<int,HitBoxesScript>();
    
    public Dictionary<int,Dictionary<int,bool>> EnemyHasHitCheck = new Dictionary<int,Dictionary<int,bool>>();
    public int boo;
    public void AddEnemy(GameObject enemy,int id){
        PhysicsScript enemyPhysicsScript = enemy.GetComponent<PhysicsScript>();
        ControlsScript  enemyControlsScript = enemy.GetComponent<ControlsScript>();
        Debug.Log("Adding unit.");
        Debug.Log("This unit is: " +enemyControlsScript);        
        Debug.Log("Adding unit.");
//        Debug.Log("This unit is: " +enemyHitBoxesScript);        
        Debug.Log("Adding unit.");
        Debug.Log("This unit is: " +enemyPhysicsScript);

        boo = totalopPhysicsScript.Count;
        Debug.Log("count: " +boo);
//        boo =totalopPhysicsScript.IndexOf(enemyPhysicsScript);
        Debug.Log("index: " +boo);
    }
    public void Removeid(int id){
        IdList.Remove(id);

    foreach (int targetid in IdList) {
            
            totalopControlsScript[targetid].enemyThrownList.Remove(id);
                        if (targetid != id) {
                                totalopControlsScript [targetid].EnemyHasHit.Remove (id);
                        }
                }
            totalopPhysicsScript.Remove(id);
        if (totalopPhysicsScript.ContainsKey (id)) {
            Debug.Log ("not deleted.");        
        }
            totalopHitBoxesScript.Remove(id);
        if (totalopHitBoxesScript.ContainsKey (id)) {
            Debug.Log ("not deleted.");        
        }

        totalopControlsScript.Remove(id);
        if (totalopControlsScript.ContainsKey (id)) {
            Debug.Log ("not deleted.");        
        }


        }    
    



    public void AddId(int id,Dictionary<int,bool> HasHitList){
        IdList.Add (id);
        EnemyHasHitCheck.Add (id,HasHitList);
        foreach(int hashitid in IdList){
            EnemyHasHitCheck[hashitid].Add(id,false);
            //Debug.Log("id"+hashitid);
            //Debug.Log("HasHit"+EnemyHasHitCheck[hashitid][id]);
        }
    }
    public void AddHitBox(HitBoxesScript hit,int id){

        totalopHitBoxesScript.Add(id,hit);
    
        Debug.Log("Adding unit.");        
        Debug.Log("This unit is: " +hit);
        
        Debug.Log("id: " +id);
    }
    public void AddPhysics(PhysicsScript phy,int id){
        
        totalopPhysicsScript.Add(id,phy);
        
        Debug.Log("Adding unit.");        
        Debug.Log("This unit is: " +phy);
        
        Debug.Log("id: " +id);
    }    
    public void AddControls(ControlsScript cnt,int id){
        
        totalopControlsScript.Add(id,cnt);
        
        Debug.Log("Adding unit.");
        Debug.Log("This unit is: " +cnt);
        Debug.Log("id: " +id);
    }
    // Use this for initialization
    void Start () {

    
    }
    

}

Main role of this code is "Handling enemy list by Object ID".
(It not have function to make Object ID.
ID is Made by character object.)
And add this script to main camera.



2.Make Mechanism to hit enemy by search  list and dictionary

This is a big part of my test (and i forgot a big part of my coding...sorry...)

(i) Make  "Hit check" dictionary each of the character
It is important part.Open UFE's ControlScript, and set

    
public Dictionary<int,bool> EnemyHasHit = new  Dictionary<int,bool>();
private int MyId;
public EnemyList enemlist;

ok.Class "EnemyList"is script made in 1.

then , in Start section, setup List.

        MyId = gameObject.GetInstanceID ();
        enemyhandler = GameObject.Find ("Main Camera");
        enemlist= enemyhandler.GetComponent<EnemyList>();
        enemlist.AddPhysics (myPhysicsScript,MyId);
        enemlist.AddHitBox(myHitBoxesScript,MyId);
        enemlist.AddControls (this, MyId);
        enemlist.AddId (MyId,EnemyHasHit);

this section is important.
In thissection,character's Id is add to dictionary by character.
And dictionary only one,and can use any character.
So,character can access each other.
But, hit flag have to make  each character.
There Is a strong reason.But I forget! hahaha

Probabry,If do not management flag list  by character,
it result"When A Hit B, damage cause A and B and C...".
It is not good.

(ii)Check enemy hit box
this is core ob mycodeing and very complex,
Big part of code need to edit.
But there is a low.
Edit is a very hassle, but it is not difficult.
So, i Showa example to how to edit

foreach(int id in enemlist.IdList){
                            if(id!=MyId){
                                if(EnemyHasHit[id]==false){        

                                    if (enemlist.totalopControlsScript[id].comboHits >= UFE.config.comboOptions.maxCombo) continue;
                                    if (!hit.groundHit && enemlist.totalopPhysicsScript[id].isGrounded()) continue;
                                    if (!hit.airHit && !enemlist.totalopPhysicsScript[id].isGrounded()) continue;
                                    if (!hit.downHit && enemlist.totalopControlsScript[id].currentState == PossibleStates.Down) continue;

                        
....
(it is a Hit part in Controlscript . I dont past all of part for UFE'Ssecret)

...
if (!hit.continuousHit) EnemyHasHit[id] = true;
(in last of hit part, this is impotant. and dont forget set false your EnemyHasHit by iterate in killcurrentmove section)                                

Core of my method is search dictionary by Id.
So,When you attack,
1.Get id List in enemlist.
2.check hit with enemy in list.
3.Give some parameter(damage,physics direction,etc...)to enemy by trough list.
4.reset hit fag

Ok. it looks alittle bit complex.but itis not difficult.
you need to search

opPhysicsScript
opControlsScript
opHitBoxesScript

and edit it

totalopPhysicsScript[id]
totalopControlsScript[id]
totalopHitBoxesScript[id]


OK?
Some parameter in PhysicsScript and Controlscript is hardly need to edit(and i completery forget where i edit),
but if you can understand my method, it isnot difficult to find where to edit.


3.Remove id from dictionary
when your character died, you need remove character's id  from list.
I made removemethod in EnemyList. so i call RemoveID.it is easy.



my method (that i remenber) is all. But i think there is many problem to success multiple enemy.
Sorry for lack of my memory...
I hope this topic help someone.

Share

Thumbs up +4 Thumbs down