Ejemplo n.º 1
0
    internal override void Update(PiavRoadAgent agent)
    {
        if (agent._desiredIncomingPath.Count > 1)
        {
            for (int i = 1; i < agent._desiredIncomingPath.Count; i++)
            {
                foreach (var possibleSegment in agent.CurrentSegments)
                {
                    if (possibleSegment._segment.Id == agent._desiredIncomingPath[i]._parentSegment.Id && possibleSegment._root > 0 && possibleSegment._root < 1)
                    {
                        agent._desiredIncomingPath.RemoveRange(0, i);
                        break;
                    }
                }
            }

            var gizmolist = new List <Vector3>();

            foreach (var tuple in agent._desiredIncomingPath)
            {
                gizmolist.Add(RoadUtilities.Calculate(tuple._parentSegment.Polynomial, (tuple._fromRoot + tuple._toRoot) / 2));
            }
            SetProjectionGizmo(gizmolist, Color.red);
        }
    }
    /// <inheritdoc />
    internal override void Update(PiavRoadAgent agent)
    {
        double        minimalDistance      = double.PositiveInfinity;
        StoppingPoint closestStoppingPoint = null;

        for (int i = 0; i < agent.CurrentStops._points.Length; i++)
        {
            if (agent.CurrentStops._points[i].Type == StoppingType.Vehicle && agent.CurrentStops._distances[i] < minimalDistance)
            {
                minimalDistance      = agent.CurrentStops._distances[i];
                closestStoppingPoint = agent.CurrentStops._points[i];
            }
        }


        for (int i = 0; i < _parentAi._profile._forcedSpeedLimitValues.Count; i++)
        {
            if (_parentAi._profile._forcedSpeedLimitValues[i]._originBehaviorType == GetType())
            {
                if (closestStoppingPoint != null)
                {
                    if (minimalDistance < closestStoppingPoint.Origin.AdditionalLength.y + closestStoppingPoint.Origin.Dimensions.y / 2.0
                        + Math.Max(2.0, closestStoppingPoint.Origin.CurrentAbsoluteSpeed * 1.5))
                    {
                        _parentAi._profile._forcedSpeedLimitValues[i] = new PiavRoadContainer.SpeedLimitation {
                            _value = closestStoppingPoint.Origin.CurrentAbsoluteSpeed * 0.9, _originBehaviorType = GetType()
                        }
                    }
                }
            }
            ;
Ejemplo n.º 3
0
    /// <inheritdoc />
    internal override void Update(PiavRoadAgent agent)
    {
        var speedTarget = _parentAi._profile.GetMinimalSpeedValue();

        if (!double.IsNaN(speedTarget))
        {
            var lowerThreshold = speedTarget * 0.9;
            var upperThreshold = speedTarget * 1.1;

            if (agent.CurrentAbsoluteSpeed < lowerThreshold)
            {
                agent.DesiredThrottle = 1;
            }
            else if (agent.CurrentAbsoluteSpeed > upperThreshold)
            {
                agent.DesiredThrottle = -1;
            }
            else
            {
                agent.DesiredThrottle = 2 * (agent.CurrentAbsoluteSpeed - lowerThreshold) / (upperThreshold - lowerThreshold) - 1;
            }
        }
        else
        {
            agent.DesiredThrottle = 0;
        }
    }
Ejemplo n.º 4
0
 private void Awake()
 {
     _parentAgent = GetComponent <PiavRoadAgent>();
     if (_parentAgent == null)
     {
         Debug.LogError("Could not initialize PiavInput, RoadAgent not found");
     }
 }
Ejemplo n.º 5
0
 internal override void Update(PiavRoadAgent agent)
 {
     if (agent._desiredIncomingPath == null || agent._desiredIncomingPath.Count <= 1)
     {
         _parentAi._profile._targetDestination = _parentContainer.FindRandomSegmentAndRoot();
         while (_parentAi._profile._targetDestination._segment.ParentLane.MyType != LaneType.Vehicle)
         {
             _parentAi._profile._targetDestination = _parentContainer.FindRandomSegmentAndRoot();
         }
         _parentAi._profile._needTargetDestination = true;
     }
 }
Ejemplo n.º 6
0
    internal override void Update(PiavRoadAgent agent)
    {
        if (agent != null && agent.CurrentSegments != null && agent.CurrentSegments.Count > 0)
        {
            var chosenSegment = new PiavRoadContainer.ValuedSegment();
            if (agent._desiredIncomingPath != null && agent._desiredIncomingPath.Count > 0)
            {
                foreach (var possibleSegment in agent.CurrentSegments)
                {
                    if (possibleSegment._segment.Id == agent._desiredIncomingPath[0]._parentSegment.Id)
                    {
                        chosenSegment = possibleSegment;
                        break;
                    }
                }
            }
            else
            {
                chosenSegment = agent.CurrentSegments[0];
            }

            if (chosenSegment._segment != null)
            {
                //Debug.Log(chosenSegment.Item1.Id + " " + chosenSegment.Item2);
                var proj = _parentContainer.ProjectPathLaneFromOrigin(agent, 3.5 + agent.Dimensions.y / 2, true);

                var target = RoadUtilities.Calculate(proj._targetSegment.Polynomial, proj._targetRoot);
                SetProjectionGizmo(new List <Vector3>()
                {
                    target
                }, Color.cyan);

                var direction = target - agent.CurrentPosition;
                direction.y = 0;

                var curDirection = agent.CurrentFacingDirection;
                curDirection.y = 0;

                var angle2 = Vector3.Angle(direction, curDirection);
                var cross  = Vector3.Cross(direction, curDirection);
                if (cross.y > 0)
                {
                    angle2 = -angle2;
                }

                //Debug.Log(angle2);

                var steer = Mathf.Clamp(angle2 / 35, -1, 1);
                agent.DesiredSteer = steer;
            }
        }
    }
Ejemplo n.º 7
0
    internal override void Update(PiavRoadAgent agent)
    {
        if (_parentContainer._dualGraph != null && agent.CurrentSegments != null && agent.CurrentSegments.Count != 0)
        {
            if (_parentAi._profile._needTargetDestination)

            {
                var s = agent.CurrentSegments[0];

                agent._desiredIncomingPath = GetPath(
                    s._segment,
                    s._root,
                    _parentAi._profile._targetDestination._segment,
                    _parentAi._profile._targetDestination._root);
                _parentAi._profile._needTargetDestination = false;
            }
        }
    }
Ejemplo n.º 8
0
    /// <inheritdoc />
    internal override void Update(PiavRoadAgent agent)
    {
        if (agent != null)
        {
            if (agent.CurrentSegments.Count > 0)
            {
                var mas = agent.CurrentSegments[0];

                if (mas._segment != null)
                {
                    for (int i = 0; i < _parentAi._profile._forcedSpeedLimitValues.Count; i++)
                    {
                        if (_parentAi._profile._forcedSpeedLimitValues[i]._originBehaviorType == GetType())
                        {
                            _parentAi._profile._forcedSpeedLimitValues[i] = new PiavRoadContainer.SpeedLimitation {
                                _value = mas._segment.ParentLane.SpeedLimit, _originBehaviorType = GetType()
                            }
                        }
                        ;
                    }
                }
            }
            else
            {
                for (int i = 0; i < _parentAi._profile._forcedSpeedLimitValues.Count; i++)
                {
                    if (_parentAi._profile._forcedSpeedLimitValues[i]._originBehaviorType == GetType())
                    {
                        _parentAi._profile._forcedSpeedLimitValues[i] = new PiavRoadContainer.SpeedLimitation {
                            _value = 0, _originBehaviorType = GetType()
                        }
                    }
                    ;
                }
            }
        }
    }
}
 internal abstract override void Update(PiavRoadAgent agent);
Ejemplo n.º 10
0
 internal abstract void Update(PiavRoadAgent agent);
    internal override void Update(PiavRoadAgent agent)
    {
        if (agent != null && agent.CurrentSegments != null && agent.CurrentSegments.Count > 0)
        {
            var chosenSegment = new PiavRoadContainer.ValuedSegment();

            if (agent._desiredIncomingPath != null && agent._desiredIncomingPath.Count > 0)
            {
                foreach (var possibleSegment in agent.CurrentSegments)
                {
                    if (possibleSegment._segment.Id == agent._desiredIncomingPath[0]._parentSegment.Id)
                    {
                        chosenSegment = possibleSegment;

                        break;
                    }
                }
            }
            else
            {
                chosenSegment = agent.CurrentSegments[0];
            }

            if (chosenSegment._segment != null)
            {
                for (int i = 0; i < _parentAi._profile._forcedSpeedLimitValues.Count; i++)
                {
                    if (_parentAi._profile._forcedSpeedLimitValues[i]._originBehaviorType == GetType())
                    {
                        double totalAngle  = 0;
                        var    projections = new List <Vector3>();

                        for (int j = 1; j <= 3; j++)
                        {
                            var proj = _parentContainer.ProjectPathLaneFromOrigin(agent, (3 + agent.CurrentAbsoluteSpeed) * j * 1.2, true);

                            var pos = RoadUtilities.Calculate(proj._targetSegment.Polynomial, proj._targetRoot);
                            pos.y = agent.CurrentPosition.y;
                            projections.Add(pos);
                            var dir = pos - agent.CurrentPosition;
                            totalAngle += Math.Abs(Vector3.Angle(dir, agent.CurrentFacingDirection));
                        }
                        totalAngle /= 3;
                        SetProjectionGizmo(projections, Color.yellow);

                        if (totalAngle < 5)
                        {
                            _parentAi._profile._forcedSpeedLimitValues[i] = new PiavRoadContainer.SpeedLimitation {
                                _value = double.PositiveInfinity, _originBehaviorType = GetType()
                            }
                        }
                        ;
                        else if (totalAngle < 35)
                        {
                            _parentAi._profile._forcedSpeedLimitValues[i] = new PiavRoadContainer.SpeedLimitation {
                                _value = 5 / ((totalAngle - 4) / 30), _originBehaviorType = GetType()
                            }
                        }
                        ;
                        else if (totalAngle < 125)
                        {
                            _parentAi._profile._forcedSpeedLimitValues[i] = new PiavRoadContainer.SpeedLimitation {
                                _value = 5 - (totalAngle - 35) / 225, _originBehaviorType = GetType()
                            }
                        }
                        ;
                        else
                        {
                            _parentAi._profile._forcedSpeedLimitValues[i] = new PiavRoadContainer.SpeedLimitation {
                                _value = 0.1, _originBehaviorType = GetType()
                            }
                        };

                        break;
                    }
                }
            }
            else
            {
                for (int i = 0; i < _parentAi._profile._forcedSpeedLimitValues.Count; i++)
                {
                    if (_parentAi._profile._forcedSpeedLimitValues[i]._originBehaviorType == GetType())
                    {
                        _parentAi._profile._forcedSpeedLimitValues[i] = new PiavRoadContainer.SpeedLimitation
                        {
                            _value = double.PositiveInfinity,
                            _originBehaviorType = GetType()
                        }
                    }
                    ;
                }
            }
        }
    }
}