Exemplo n.º 1
0
    public void Init()
    {
        Simulator.Instance.setTimeStep(0.15f);
        Simulator.Instance.setAgentDefaults(neibourDist, maxNeibours, timeHorizon, obstacleTimeHorizon, radius, maxSpeed, new RVO.Vector2(0.0f, 0.0f));
        for (int i = 0; i < agentCount; i++)
        {
            RVO.Vector2 pos = circleRadius *
                              new RVO.Vector2((float)Math.Cos(i * 2.0f * Math.PI / agentCount),
                                              (float)Math.Sin(i * 2.0f * Math.PI / agentCount));
            Simulator.Instance.addAgent(pos);
            dirs.Add(RVOMath.normalize(-Simulator.Instance.getAgentPosition(i) - Simulator.Instance.getAgentPosition(i)));
            goals.Add(-Simulator.Instance.getAgentPosition(i));

            GameObject go = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            go.transform.position = new Vector3(pos.x(), 120, pos.y());
            agents.Add(go);
        }
        ConvertToObstacle();
        inited = true;
    }
Exemplo n.º 2
0
    private void Update()
    {
        if (inited == false)
        {
            return;
        }

        //if ((Time.time - lastTime) > 0.25f)
        //{
        //    lastTime = Time.time;
        //    for (int i = 0; i < goals.Count; i++)
        //    {
        //        goals[i] += dirs[i] * 0.8f;
        //        Debug.DrawLine(goals[i].ToVec3XZ(),goals[i].ToVec3XZ()+Vector3.up*5f,Color.cyan,0.25f);
        //    }
        //}
        if (ReachedGoal() == false)
        {
            SetPreferredVelocities();
            Simulator.Instance.doStep();
        }
        for (int i = 0; i < agents.Count; i++)
        {
            vec2       = Simulator.Instance.getAgentPosition(i);
            realPos.x  = vec2.x();
            realPos.z  = vec2.y();
            vec2       = Simulator.Instance.getAgentVelocity(i);
            velocity.x = vec2.x_;
            velocity.z = vec2.y_;
            agentPos   = agents[i].transform.position;
            Debug.DrawLine(agentPos + Vector3.up * 1f,
                           agentPos + velocity.normalized * 2.5f + Vector3.up * 1f,
                           Color.green, Time.deltaTime);
            Debug.DrawLine(realPos, realPos + Vector3.up * 10, Color.red, Time.deltaTime);
            agents[i].transform.position = Vector3.Lerp(agentPos, realPos, Time.deltaTime * RVOMath.abs(Simulator.Instance.getAgentVelocity(i)));
        }
    }
Exemplo n.º 3
0
 private Vector3 ToVec3(RVO.Vector2 vec)
 {
     return(new Vector3(vec.x(), 0, vec.y()));
 }