示例#1
0
    public void AddObstacle(int index)
    {
        if (NextDistance > path.length)
        {
            ++cont;
            NextDistance = NextDistance % path.length;
        }
        if (NextDistance > middle_point)
        {
            half = 1;
        }
        else
        {
            half = 0;
        }

        string name = "Obstacles" + cont + half;

        GetParentObject(name);
        Vector3    position = path.GetPointAtDistance(NextDistance, endOfPathInstruction);
        Vector3    upward   = path.GetDirectionAtDistance(NextDistance, endOfPathInstruction);
        Vector3    forward  = path.GetNormalAtDistance(NextDistance, endOfPathInstruction);
        Quaternion rotation = Quaternion.LookRotation(forward, upward);

        Instantiate(obstacles[index], position, rotation, obstacles_object.transform);
        NextDistance += DistanceGap;
    }
示例#2
0
        private void Update_Internal(float delta)
        {
            if (!stopped)
            {
                if (pathCreator != null)
                {
                    path = pathCreator.path;
                }

                if (path == null)
                {
                    return;
                }

                distanceTravelled += speed * delta;
                transform.position = path.GetPointAtDistance(distanceTravelled, endOfPathInstruction);
                if (updateRotation)
                {
                    if (useDirectionToRotate)
                    {
                        var rot = path
                                  .GetDirectionAtDistance(distanceTravelled, endOfPathInstruction).LookRotation();
                        rot.Set(x: 0, z: 0);
                        transform.rotation = rot;
                    }
                    else
                    {
                        transform.rotation = path.GetRotationAtDistance(distanceTravelled, endOfPathInstruction);
                    }
                }
            }
        }
示例#3
0
    void Update()
    {
        _distanceTravelled += _speed * Time.deltaTime;

        var travelPercent = _distanceTravelled / _path.length;

        if (travelPercent > _startToFleePercent)
        {
            _startToFleeParticle.gameObject.SetActive(true);
        }

        if (travelPercent >= 1f)
        {
            OnDuckFlee?.Invoke(this);
            _OnDuckFlee.Invoke();

            Destroy(gameObject);
            return;
        }

        transform.position = _path.GetPointAtDistance(_distanceTravelled);
        var forward = _path.GetDirectionAtDistance(_distanceTravelled);
        var rot     = Quaternion.LookRotation(forward, Vector3.up);

        transform.rotation = rot;
    }
示例#4
0
    public void GenerateTube(bool file)
    {
        string name = "Tube";
        var    generated_tranform = transform.Find(name);

        if (generated_tranform != null)
        {
            DestroyImmediate(generated_tranform.gameObject);
            Debug.Log("destroyed");
        }
        tube = Create(name, gameObject);
        Debug.Log("create tube");

        PathCreator path_creator = gameObject.GetComponent <PathCreator>();

        if (path_creator != null)
        {
            VertexPath path = path_creator.path;

            /*if (file)
             * {
             *  BezierPath bp = path_creator.LoadPath();
             *  path = new VertexPath(bp, transform);
             * }
             * else
             * {
             *  path = path_creator.path;
             * }*/

            Debug.Log("got path");
            for (float distance = 0; distance < path.length; distance += 0.2f)
            {
                Vector3    position = path.GetPointAtDistance(distance, endOfPathInstruction);
                Vector3    upward   = path.GetDirectionAtDistance(distance, endOfPathInstruction);
                Vector3    forward  = path.GetNormalAtDistance(distance, endOfPathInstruction);
                Quaternion rotation = Quaternion.LookRotation(forward, upward);
                Instantiate(segment, position, rotation, tube.transform);
            }
        }
    }
示例#5
0
    //public override void CollectObservations(VectorSensor sensor)
    //{
    //    // # Basic information
    //    Rigidbody rBody = GetComponent<Rigidbody>();
    //    // Agent positions & velocity
    //    sensor.AddObservation(this.transform.localPosition);
    //    sensor.AddObservation(rBody.velocity);
    //    // # Collect Path's observations
    //    float centerDistance = vertexPath.GetClosestDistanceAlongPath(this.transform.localPosition);
    //    for (int d = tickerStart; d <= tickerEnd; d++)
    //    {
    //        float distance = centerDistance + d * tickerSpace;
    //        Vector3 point = vertexPath.GetPointAtDistance(distance, EndOfPathInstruction.Loop);
    //        Vector3 normal = vertexPath.GetNormalAtDistance(distance, EndOfPathInstruction.Loop);

    //        AddObservationInXYZMode(sensor, point);
    //        AddObservationInXYZMode(sensor, normal);
    //    }
    //    // # Padding observations
    //    // If custom setting will have too more observations and cause the buffer overflow, We
    //    // must warn user (in Pyhon interface level).
    //    // Here we are padding the observation buffer with all zero
    //    int MaxObservationSize = GetComponent<BehaviorParameters>().BrainParameters.VectorObservationSize;
    //    for (int i = 0; i < MaxObservationSize - ObservationSize; i++)
    //        sensor.AddObservation(0);
    //}
    public override void CollectObservations(VectorSensor sensor)
    {
        // # Basic information
        Rigidbody rBody = GetComponent <Rigidbody>();

        // Agent velocity
        sensor.AddObservation(this.transform.localPosition);
        sensor.AddObservation(rBody.velocity);
        // # Collect Path's basic information
        float   centerDistance = vertexPath.GetClosestDistanceAlongPath(this.transform.localPosition);
        Vector3 direction      = vertexPath.GetDirectionAtDistance(centerDistance);
        // Check clockwise direction & determine ticker's start and end
        bool clockwise = (Vector3.Dot(rBody.velocity, direction) >= 0);
        int  t_s       = clockwise ? tickerStart : -tickerEnd;
        int  t_e       = clockwise ? tickerEnd : -tickerStart;

        // # Collect Path's observations
        for (int d = t_s; d <= t_e; d++)
        {
            float   distance = centerDistance + d * tickerSpace;
            Vector3 point    = vertexPath.GetPointAtDistance(distance, EndOfPathInstruction.Loop);
            Vector3 normal   = vertexPath.GetNormalAtDistance(distance, EndOfPathInstruction.Loop);
            AddObservationInXYZMode(sensor, point - this.transform.localPosition);
            AddObservationInXYZMode(sensor, normal);
        }
        // # Padding observations
        // If custom setting will have too more observations and cause the buffer overflow, We
        // must warn user (in Pyhon interface level).
        // Here we are padding the observation buffer with all zero
        int MaxObservationSize = GetComponent <BehaviorParameters>().BrainParameters.VectorObservationSize;

        for (int i = 0; i < MaxObservationSize - ObservationSize; i++)
        {
            sensor.AddObservation(0);
        }
    }