Beispiel #1
0
    public void reportColliderExit(Collider col, string colliderName)
    {
        if (!destroying)
        {
            CollisionObj rawCollisionObj = getColliderType(col);
            if (rawCollisionObj != null)
            {
                VehicleCollisionObj vehicleCollisionObj = rawCollisionObj.typeName == VehicleCollisionObj.NAME ? (VehicleCollisionObj)rawCollisionObj : null;
                HumanCollisionObj   humanCollisionObj   = rawCollisionObj.typeName == HumanCollisionObj.NAME ? (HumanCollisionObj)rawCollisionObj : null;

                if (vehicleCollisionObj != null)
                {
                    removeVehicleInVision(vehicleCollisionObj);
                }
                else if (humanCollisionObj != null)
                {
                    HumanLogic otherHuman = humanCollisionObj.Human;
                    waitForHumans.Remove(otherHuman);
                }
            }
        }
    }
Beispiel #2
0
 public override void Update()
 {
     proxySprite.Set(x, y);
     CollisionObj.UpdatePos(x, y);
 }
Beispiel #3
0
    public void reportCollision(Collider col, string colliderName)
    {
        // ColliderName = "BODY" or "VISION"
        if (!destroying)
        {
            CollisionObj rawCollisionObj = getColliderType(col);
            if (rawCollisionObj != null)
            {
                VehicleCollisionObj vehicleCollisionObj = rawCollisionObj.typeName == VehicleCollisionObj.NAME ? (VehicleCollisionObj)rawCollisionObj : null;
                HumanCollisionObj   humanCollisionObj   = rawCollisionObj.typeName == HumanCollisionObj.NAME ? (HumanCollisionObj)rawCollisionObj : null;

                if (vehicleCollisionObj != null)
                {
                    setVehicleInVision(vehicleCollisionObj);
                }
                else if (humanCollisionObj != null)
                {
                    HumanLogic otherHuman   = humanCollisionObj.Human;
                    bool       shouldDecide = humanId < otherHuman.humanId;
                    if (colliderName == "VISION")
                    {
                        // Scenarios:
                        // Meeting in intersection, moving towards same point
                        // One walking faster, moving in same direction (towards same point)
                        // Meeting, not moving towards same point
                        // One or both have already deviated from target, meeting on the way to temporary point
                        float angle = Quaternion.Angle(transform.rotation, otherHuman.transform.rotation);
                        if (shouldDecide || angle < 20f)
                        {
                            if (angle >= 20f && angle <= 160f)
                            {
                                // Walking with an angle towards each other - one should wait
                                otherHuman.waitForAWhile();
                            }
                            else if (angle < 20f)
                            {
                                // Walking alongside, they divide their speed, the one ahead goes a tiny bit quicker
                                float totalWalkingSpeed = speedFactor + otherHuman.speedFactor;
                                speedFactor            = totalWalkingSpeed * 0.45f;
                                otherHuman.speedFactor = totalWalkingSpeed * 0.55f;
                            }
                            else
                            {
                                // Walking towards each other, decide one deviation point for each
                                Vector3    otherPosition = otherHuman.transform.position;
                                Quaternion otherRotation = otherHuman.transform.rotation;

                                Vector3 otherHumanToMe      = transform.position - otherPosition;
                                Vector3 otherPersonMovement = otherRotation * Vector3.right;
                                bool    isToTheRight        = Vector3.Cross(otherPersonMovement, otherHumanToMe).z < 0;

                                Vector3 meetingPosition = transform.position + (otherPosition - transform.position) / 2f;

                                deviationTarget                 = meetingPosition + Quaternion.Euler(0f, 0f, transform.rotation.eulerAngles.z + (isToTheRight ? 90f : -90f)) * BODY_WIDTH;
                                timedDeviationTarget            = null;
                                otherHuman.deviationTarget      = meetingPosition + Quaternion.Euler(0f, 0f, otherRotation.eulerAngles.z + (isToTheRight ? 90f : -90f)) * BODY_WIDTH;
                                otherHuman.timedDeviationTarget = null;
                            }
                        }
                    }
                    else if (colliderName == "BODY")
                    {
                        if (walkPath.Count > 0 && otherHuman.walkPath.Count > 0)
                        {
                            float ourDistance   = Misc.getDistance(transform.position, walkPath [0]);
                            float otherDistance = Misc.getDistance(otherHuman.transform.position, otherHuman.walkPath [0]);
                            if (ourDistance > otherDistance || (ourDistance == otherDistance && !shouldDecide))
                            {
                                if (!otherHuman.waitForHumans.Contains(this))
                                {
                                    waitForHumans.Add(otherHuman);
                                }
                            }
                        }
                    }
                }
            }
        }
    }