コード例 #1
0
ファイル: CmvAgent.cs プロジェクト: MikeWise2718/MlaCrowdMove
    public void SetupAgent(CmvAgMan cmvAgMan)
    {
        Debug.Log($"  SetupAgent for {name}");
        this.cmvAgMan = cmvAgMan;
        SetupAgentSpaceType(SpaceType.Continuous);
        //LazyInitialize();// gets called when component is added in OnEnable

        area    = cmvAgMan.area;
        ground  = cmvAgMan.ground;
        redGoal = cmvAgMan.redGoal;
        //useVectorObs = true;

        // Create body
        avatar                  = GameObject.CreatePrimitive(PrimitiveType.Capsule);
        avatar.name             = "body";
        avatar.transform.parent = transform;
        cmvagbod                = avatar.AddComponent <CmvAgentBody>();
        var visor = GameObject.CreatePrimitive(PrimitiveType.Cube);
        var clder = visor.GetComponent <Collider>();

        clder.enabled              = false;
        visor.transform.parent     = avatar.transform;
        visor.transform.localScale = new Vector3(0.95f, 0.25f, 0.5f);
        visor.transform.position   = new Vector3(0, 0.5f, -0.25f);
        CmvAgentBody.SetColorOfGo(visor, Color.black);
        maxStep = cmvAgMan.cmvSettings.maxstep;

        cmvagbod.Init(this);

        groundRenderer = ground.GetComponent <Renderer>();
        groundMaterial = groundRenderer.material;
        cmvagbod.InitializeAgentBody();
    }
コード例 #2
0
    public void SetupAgent(CmvAgMan cmvAgMan)
    {
        this.cmvAgMan = cmvAgMan;

        // Initialize agent parameters
        //brain = cmvAgMan.brain;
        area            = cmvAgMan.area;
        ground          = cmvAgMan.ground;
        redGoal         = cmvAgMan.redGoal;
        agentParameters = cmvAgMan.agentParameters;

        useVectorObs = true;

        // Create body
        avatar                  = GameObject.CreatePrimitive(PrimitiveType.Capsule);
        avatar.name             = "body";
        avatar.transform.parent = transform;
        cmvagbod                = avatar.AddComponent <CmvAgentBody>();
        var visor = GameObject.CreatePrimitive(PrimitiveType.Cube);
        var clder = visor.GetComponent <Collider>();

        clder.enabled              = false;
        visor.transform.parent     = avatar.transform;
        visor.transform.localScale = new Vector3(0.95f, 0.25f, 0.5f);
        visor.transform.position   = new Vector3(0, 0.5f, -0.25f);
        CmvAgentBody.SetColorOfGo(visor, Color.black);

        cmvagbod.Init(this);
        //var bhp = GetComponent<BehaviorParameters>();
        //bhp.m_BehaviorName = "CrowdMove";
        ////bhp.m_UseHeuristic = true;
        //var bp = bhp.brainParameters;
        //bp.vectorActionSpaceType = SpaceType.Continuous;
        //bp.vectorObservationSize = 36;
        //bp.vectorActionSize = new int[] { 2 };
        //bp.vectorActionDescriptions = new string[] { "action1", "action2" };
        //this.sType = bp.vectorActionSpaceType;

        //SetupAgentSpaceType(SpaceType.Continuous);


        // Create banner textmeshpro
        //var text = name + "\n" + name;
        ////bannertmp = GraphAlgos.GraphUtil.MakeTextGo(gameObject, text, 1.5f, fvek: Vector3.back);
        //bannergo = bannertmp.transform.parent.gameObject;
        //bannergo.name = "banner";

        groundRenderer = ground.GetComponent <Renderer>();
        groundMaterial = groundRenderer.material;
        cmvagbod.InitializeAgentBody();
    }
コード例 #3
0
ファイル: CmvAgent.cs プロジェクト: MikeWise2718/MlaCrowdMove
    public void MoveAgent(float[] act)
    {
        Vector3 dirToGo   = Vector3.zero;
        Vector3 rotateDir = Vector3.zero;
        Vector3 fwdDir    = avatar.transform.forward;
        Vector3 upDir     = avatar.transform.up;

        if (sType == SpaceType.Continuous)
        {
            dirToGo   = fwdDir * Mathf.Clamp(act[0], -1f, 1f);
            rotateDir = upDir * Mathf.Clamp(act[1], -1f, 1f);
        }
        else
        {
            int action = Mathf.FloorToInt(act[0]);
            switch (action)
            {
            case 1:
                dirToGo = fwdDir * 1f;
                break;

            case 2:
                dirToGo = fwdDir * -1f;
                break;

            case 3:
                rotateDir = upDir * 1f;
                break;

            case 4:
                rotateDir = upDir * -1f;
                break;
            }
        }

        var forceVek = dirToGo * cmvAgMan.cmvSettings.agentRunSpeed;
        var dist     = Vector3.Magnitude(avatar.transform.position - lastpos);
        var force    = Vector3.Magnitude(forceVek);

        //Debug.Log("Move "+name+" "+sType+" rot:"+rotateDir.ToString("F1")+" force:"+forceVek.ToString("F3")+" dst:"+dist.ToString("f1"));
        if (bannertmp != null)
        {
            var hitstring = cmvagbod.rpi.GetHitObs();
            bannertmp.text = name + "\n" + hitstring + "\n" + hitFlashTimeMark.ToString("f1");
        }
        if (avatar != null)
        {
            Color c         = c0;
            var   stepCount = StepCount;
            if (Time.time - hitFlashTimeMark < flashTime)
            {
                c = c4;
            }
            else if (stepCount < 0.05f * maxStep)
            {
                var lamb = stepCount / (0.05f * maxStep);
                c = Color.Lerp(c0, c1, lamb);
            }
            else
            {
                var lamb = stepCount / (1.0f * maxStep);
                c = Color.Lerp(c1, c2, lamb);
            }
            CmvAgentBody.SetColorOfGo(avatar, c);
        }
        cmvagbod.AddMovement(rotateDir, forceVek, ForceMode.VelocityChange);
        cmvagbod.SyncToBody(bannergo);
        lastpos = avatar.transform.position;
        nmoves++;
    }