示例#1
0
 protected virtual void SetObstacleState()
 {
     if (obstacleTimer.isOnCooldown("Electric") == false)
     {
         obstacleState = ObstacleState.Run;
     }
 }
示例#2
0
    // Start is called before the first frame update
    void Start()
    {
        ConstWheelDist = (Wheel_FL.position - Wheel_BL.position).magnitude;

        _carState.position     = transform.position;
        _carState.turnTheta    = 0;
        _carState.speed        = 0;
        _carState.goalPosition = new Vector2(Goal.position.x, Goal.position.y);

        ObstacleState o1 = new ObstacleState();

        o1.position = new Vector2(0, 0);
        o1.radius   = 5;
        _obstacleStates.Add(o1);

        ObstacleState o2 = new ObstacleState();

        o2.position = new Vector2(20, 0);
        o2.radius   = 5;
        _obstacleStates.Add(o2);

        ObstacleState o3 = new ObstacleState();

        o3.position = new Vector2(-20, 0);
        o3.radius   = 5;
        _obstacleStates.Add(o3);

        resultLayers       = TrainRearAxelBicycleModel();
        trained            = true;
        transform.position = _carState.position;
    }
 public void UpdateSettings(ObstacleState upperLeftSensor, ObstacleState leftSensor, ObstacleState upperRightSensor, ObstacleState rightSensor, LogicOp operation)
 {
     this.upperLeftSensor  = upperLeftSensor;
     this.leftSensor       = leftSensor;
     this.upperRightSensor = upperRightSensor;
     this.rightSensor      = rightSensor;
     this.operation        = operation;
 }
示例#4
0
 /// <summary>
 /// Changing enemies states
 /// </summary>
 protected virtual void ChangeState(ObstacleState obstacleState)
 {
     if (this.obstacleState != obstacleState)
     {
         prevState          = this.obstacleState;
         this.obstacleState = obstacleState;
     }
 }
 public ObstacleAction(string key, ObstacleState upperLeftSensor, ObstacleState leftSensor, ObstacleState upperRightSensor, ObstacleState rightSensor, LogicOp operation)
 {
     this.key              = key;
     this.upperLeftSensor  = upperLeftSensor;
     this.leftSensor       = leftSensor;
     this.upperRightSensor = upperRightSensor;
     this.rightSensor      = rightSensor;
     this.operation        = operation;
 }
示例#6
0
    private void Awake()
    {
        containsEnemy          = false;
        destroyingInGame       = false;
        treasureObstacleLinked = false;

        state = ObstacleState.Idle;

        animator = GetComponent <Animator>();
    }
示例#7
0
 private void Going()
 {
     if (Mathf.Abs(transform.position.y - finalposition.y) >= 0.1f)
     {
         transform.position += transform.up * Time.deltaTime * speed;
     }
     else
     {
         obstate = ObstacleState.leaving;
     }
 }
示例#8
0
 private void Leaving()
 {
     if (Mathf.Abs(transform.position.y - startposition.y) >= 0.1f)
     {
         transform.position -= transform.up * Time.deltaTime * speed;
     }
     else
     {
         obstate = ObstacleState.going;
     }
 }
    void Start()
    {
        joystick       = FindObjectOfType <Joystick>();
        obstacleStates = FindObjectOfType <ObstacleState>();

        for (int i = 0; i < obstacleStates.transform.childCount; i++)
        {
            if (obstacleStates.transform.GetChild(i).GetComponent <CombinigColors>() == null)
            {
                cancombiningAmount++;
            }
        }
    }
示例#10
0
    void Start()
    {
        obstate       = ObstacleState.going;
        startposition = transform.position;

        if (transform.rotation.x == 0)
        {
            finalposition = startposition + movementVector;
        }
        else
        {
            finalposition = startposition - movementVector;
        }
    }
示例#11
0
    //SpawnObstacle
    public void SpawnObstacle()
    {
        ObstacleState whichObstacle = (ObstacleState)UnityEngine.Random.Range(0, obStateCount);

        SpawnPlayer();

        if (whichObstacle == ObstacleState.Spinner)
        {
            SpinnerSpawn();
        }
        else if (whichObstacle == ObstacleState.Slice)
        {
            SliceSpawn();
        }
    }
示例#12
0
        protected override void SaveSettings()
        {
            ObstacleState upperLeft  = (ObstacleState)Enum.ToObject(typeof(ObstacleState), this.cbUpperLeft.SelectedIndex);
            ObstacleState left       = (ObstacleState)Enum.ToObject(typeof(ObstacleState), this.cbLeft.SelectedIndex);
            ObstacleState upperRight = (ObstacleState)Enum.ToObject(typeof(ObstacleState), this.cbUpperRight.SelectedIndex);
            ObstacleState right      = (ObstacleState)Enum.ToObject(typeof(ObstacleState), this.cbRight.SelectedIndex);

            LogicOp operation = LogicOp.And;

            if (this.rbOr.Checked)
            {
                operation = LogicOp.Or;
            }

            this.action.UpdateSettings(upperLeft, left, upperRight, right, operation);
        }
        /// <summary>
        /// 查询障碍物
        /// </summary>
        /// <param name="name"> mapPos的名字</param>
        /// <param name="dirt">位置  0-3 代表 上下左右</param>
        /// <returns> 0:没有障碍物 1:有障碍物 2 : 墙  4:没有此name 3:下一步会有cell的障碍物</returns>
        public int  QuaryObstacle(string name, int dirt)
        {
            // 如果没有存在这个name
            int           value         = 4;
            ObstacleState obstacleState = IsObstacleofNext(name, dirt);

            if (obstacleState != ObstacleState.Nothing)
            {
                return(1);                                    // 有障碍
            }
            if (obstacle.ContainsKey(name) && dirt < DirtNum) // 防止溢出
            {
                value = obstacle[name][dirt];
            }


            return(value);
        }
示例#14
0
    public void setState(ObstacleState newState)
    {
        switch (newState)
        {
        case ObstacleState.Stopped:
            StateUpdate = stoppedUpdate;
            break;

        case ObstacleState.Moving:
            StateUpdate = doMovement;
            break;

        default:
            throw new System.ArgumentOutOfRangeException();
        }

        currentState = newState;
    }
示例#15
0
    private IEnumerator GetPushedCoroutine(Node targetNode, bool twoTreasuresMerged = false)
    {
        coroutineRunning = true;

        while (true)
        {
            if (transform.position == targetNode.worldPosition)
            {
                ObstaclePushedToEnd(twoTreasuresMerged);
                coroutineRunning         = false;
                getPushedCoroutineObject = null;
                yield break;
            }
            state = ObstacleState.Moving;
            transform.position = Vector3.MoveTowards(transform.position, targetNode.worldPosition, obstaclePushSpeed * Time.deltaTime);
            yield return(null);
        }
    }
示例#16
0
    public void ObstaclePushedToEnd(bool twoTreasuresMerged)
    {
        state = ObstacleState.Idle;

        if (!ObstaclesManager.instance.allTreasuresMerged)
        {
            List <Obstacle> treasureObstacles = new List <Obstacle>();
            for (int i = 0; i < ObstaclesManager.instance.totalObstaclesWithTreasure; i++)
            {
                treasureObstacles.Add(ObstaclesManager.instance.obstaclesList[i]);
            }

            //If this treasure was linked with another treasure and then moved away from the link, break the link.
            if (hasTreasure && linkedTreasure != null && !twoTreasuresMerged)
            {
                TreasureLinkBroken();
            }

            //If this treasure was merged with another treasure.
            if (twoTreasuresMerged && !ObstaclesManager.instance.allTreasuresMerged)
            {
                TreasuresLinked(linkedTreasure);

                bool allTreasuresAreLinked = true;
                for (int i = 0; i < treasureObstacles.Count; i++)
                {
                    if (!ObstaclesManager.instance.obstaclesList[i].treasureObstacleLinked)
                    {
                        allTreasuresAreLinked = false;
                        break;
                    }
                }

                //If all Treasures are connected
                CheckAllTreasuresMerged(allTreasuresAreLinked, treasureObstacles);
            }
        }

        //Kill attached enemy, if any.
        KillAttachedEnemies();
    }
        public ObstacleAction(string key, XmlElement properties)
        {
            this.key = key;
            if (properties.Name != "properties")
            {
                throw new ActionException("Can't create the action");
            }
            foreach (XmlElement property in properties.ChildNodes)
            {
                switch (property.Name)
                {
                case "version":
                    break;

                case "upperLeftSensor":
                    this.upperLeftSensor = (ObstacleState)Enum.Parse(typeof(ObstacleState), property.InnerText);
                    break;

                case "leftSensor":
                    this.leftSensor = (ObstacleState)Enum.Parse(typeof(ObstacleState), property.InnerText);
                    break;

                case "upperRightSensor":
                    this.upperRightSensor = (ObstacleState)Enum.Parse(typeof(ObstacleState), property.InnerText);
                    break;

                case "rightSensor":
                    this.rightSensor = (ObstacleState)Enum.Parse(typeof(ObstacleState), property.InnerText);
                    break;

                case "operation":
                    this.operation = (LogicOp)Enum.Parse(typeof(LogicOp), property.InnerText);
                    break;

                default:
                    throw new ProjectException("Error el crear la acción");
                }
            }
        }
        public static GridObstacleState FromObstacleState(ObstacleState obst, GridCarModelState state)
        {
            double d   = ComMath.Normal(Math.Sqrt(obst.pp.position.X * obst.pp.position.X + obst.pp.position.Y * obst.pp.position.Y), GridCarModelState.MIN_DIST, GridCarModelState.MAX_DIST, 0, 1);
            double a   = ComMath.Normal(state.TargetDist, GridCarModelState.MIN_DIST, GridCarModelState.MAX_DIST, 0, 1);
            double ang = Math.PI - (Math.Atan2(obst.pp.position.Y, obst.pp.position.X) + Math.PI) + state.TargetAngle - state.TargetFinishAngle;

            if (ang > Math.PI)
            {
                ang -= 2 * Math.PI;
            }
            if (ang < -Math.PI)
            {
                ang += 2 * Math.PI;
            }

            double AA       = -2 * d * Math.Cos(ang);
            double BB       = d * d;
            double obstdist = Math.Sqrt(a * a + BB + AA * a);
            double obstang  = state.TargetAngle + Math.Sign(ang) * Math.Acos((a * a + obstdist * obstdist - d * d) / (2 * a * obstdist));

            GridObstacleState gos = new GridObstacleState(obstdist, obstang, obst.radius);

            return(gos);
        }
    public void UpdateTransparancy()
    {
        Vector3 headPos            = DepthRayManager.Instance.HeadPosition;
        Vector3 rayDirection       = DepthRayManager.Instance.RayDirection;
        float   distanceMarkerHead = DepthRayManager.Instance.DistanceHeadDepthMarker;

        Vector3 dirHeadObj = transform.position - headPos;

        angleBetweenRayObj = Vector3.Angle(rayDirection, dirHeadObj);

        float distanceObjHead = Vector3.Distance(transform.position, headPos);

        if (angleBetweenRayObj < 30 && angleBetweenRayObj > -30 &&
            distanceMarkerHead > distanceObjHead - 0.05)
        {
            if (ClickManager.Instance.CurrentFocusedObject == gameObject)
            {
                state = ObstacleState.InFocusTransparent;
            }
            else
            {
                state = ObstacleState.Transparent;
            }
        }
        else
        {
            if (ClickManager.Instance.CurrentFocusedObject == gameObject)
            {
                state = ObstacleState.InFocus;
            }
            else
            {
                state = ObstacleState.Default;
            }
        }
    }
示例#20
0
 protected void NewWaitTime()
 {
     waitTimer     = Random.Range(Obstacle.WaitingTimeMin, Obstacle.WaitingTimeMax);
     obstacleState = ObstacleState.Waiting;
 }
 private void Start()
 {
     material     = GetComponent <Renderer>().material;
     defaultColor = material.color;
     state        = ObstacleState.Default;
 }
示例#22
0
    void FixedUpdate()
    {
        //This if statement will query the Planner for a new plan every second
        if (frameCounter++ % (int)(1.0f / Time.fixedDeltaTime) == 0)
        {
            isAggresive = myRand.Next(0, 11) == 0;
            if (currentState != null && currentState.otherCars != null && currentState.otherCars.Length == 0)
            {
                isAggresive = false;
            }


            currentState       = new State();// Generate a state representing the world to be passed to the HTNPlanner
            currentState.myCar = new CarState(myCarController.carUniqueID, transform.position, GetComponent <Rigidbody>().velocity, transform.forward);
            if (allCars.Length > 0)
            {
                int otherCarCount = 0;

                foreach (GameObject car in allCars)
                {
                    if (car == gameObject)
                    {
                        continue;
                    }
                    if (car == null)
                    {
                        continue;
                    }
                    otherCarCount++;
                }
                currentState.otherCars = new CarState[otherCarCount];
                otherCarCount          = 0;
                foreach (GameObject car in allCars)
                {
                    if (car == gameObject)
                    {
                        continue;
                    }
                    if (car == null)
                    {
                        continue;
                    }
                    currentState.otherCars[otherCarCount++] = new CarState(car.GetComponent <CarController>().carUniqueID, car.transform.position, car.GetComponent <Rigidbody>().velocity, car.transform.forward);
                }
            }


            if (GameLogic.myInstance != null)
            {
                System.Collections.Generic.List <GameObject> obstacleList = GameLogic.myInstance.obstacleList;
                ObstacleState[] obstacles = new ObstacleState[obstacleList.Count];

                for (int i = 0; i < obstacleList.Count; i++)
                {
                    Vector3   vel        = new Vector3(0, 0, 0);
                    Rigidbody obstacleRB = obstacleList[i].transform.GetComponent <Rigidbody>();
                    if (obstacleRB != null)
                    {
                        vel = obstacleRB.velocity;
                    }
                    obstacles[i] = new ObstacleState(obstacleList[i].transform.position, vel, obstacleList[i].transform.forward, obstacleList[i].GetComponent <MeshRenderer>().bounds);
                }
                currentState.obstacles = obstacles;
            }

            //Use raycasting to calculate the direction of the track
            float   zPos   = Mathf.Max(myCarController.GetComponent <Rigidbody>().velocity.z * 1.0f, 5.0f);
            Vector3 midPos = new Vector3(transform.position.x, 0.5f, transform.position.z + zPos);

            Ray          targetRay = new Ray(midPos - new Vector3(1, 0, 0) * rayWidth / 2, new Vector3(1, 0, 0));
            RaycastHit[] hits      = Physics.RaycastAll(targetRay, rayWidth, 1 << LayerMask.NameToLayer("AIGuide"));
            Vector3[]    targetPos = new Vector3[hits.Length];
            for (int i = 0; i < hits.Length; i++)
            {
                targetPos[i] = hits[i].point;
            }
            currentState.targetPositions = targetPos;


            //If cannot find road, assume it is lost somehow - destroy car to respawn.
            if (currentState.targetPositions.Length == 0)
            {
                GameLogic.myInstance.DestroyCar(myCarController.myPlayerData, true);
                Debug.LogWarning("Error : Could not find target position for car " + transform.gameObject.name + ". Killing car");
            }

            //Set the waitHandle to make sure that the planner can retrieve a new planning
            waitHandle.Set();
        }
    }
    void FixedUpdate()
    {
        //This if statement will query the Planner for a new plan every second
        if (frameCounter++ % (int)(1.0f / Time.fixedDeltaTime) == 0)
        {
            isAggresive = myRand.Next(0, 11) == 0;
            if (currentState != null && currentState.otherCars != null && currentState.otherCars.Length == 0)
                isAggresive = false;

            currentState = new State();// Generate a state representing the world to be passed to the HTNPlanner
            currentState.myCar = new CarState(myCarController.carUniqueID, transform.position, GetComponent<Rigidbody>().velocity, transform.forward);
            if (allCars.Length > 0)
            {
                int otherCarCount = 0;

                foreach (GameObject car in allCars)
                {
                    if (car == gameObject) continue;
                    if (car == null) continue;
                    otherCarCount++;
                }
                currentState.otherCars = new CarState[otherCarCount];
                otherCarCount = 0;
                foreach (GameObject car in allCars)
                {
                    if (car == gameObject) continue;
                    if (car == null) continue;
                    currentState.otherCars[otherCarCount++] = new CarState(car.GetComponent<CarController>().carUniqueID, car.transform.position, car.GetComponent<Rigidbody>().velocity, car.transform.forward);
                }
            }

            if (GameLogic.myInstance != null)
            {
                System.Collections.Generic.List<GameObject> obstacleList = GameLogic.myInstance.obstacleList;
                ObstacleState[] obstacles = new ObstacleState[obstacleList.Count];

                for (int i = 0; i < obstacleList.Count; i++)
                {
                    Vector3 vel = new Vector3(0, 0, 0);
                    Rigidbody obstacleRB = obstacleList[i].transform.GetComponent<Rigidbody>();
                    if (obstacleRB != null)
                        vel = obstacleRB.velocity;
                    obstacles[i] = new ObstacleState(obstacleList[i].transform.position, vel, obstacleList[i].transform.forward, obstacleList[i].GetComponent<MeshRenderer>().bounds);
                }
                currentState.obstacles = obstacles;
            }

            //Use raycasting to calculate the direction of the track
            float zPos = Mathf.Max(myCarController.GetComponent<Rigidbody>().velocity.z * 1.0f, 5.0f);
            Vector3 midPos = new Vector3(transform.position.x, 0.5f, transform.position.z + zPos);

            Ray targetRay = new Ray(midPos - new Vector3(1, 0, 0) * rayWidth / 2, new Vector3(1, 0, 0));
            RaycastHit[] hits = Physics.RaycastAll(targetRay, rayWidth, 1 << LayerMask.NameToLayer("AIGuide"));
            Vector3[] targetPos = new Vector3[hits.Length];
            for (int i = 0; i < hits.Length; i++)
                targetPos[i] = hits[i].point;
            currentState.targetPositions = targetPos;

            //If cannot find road, assume it is lost somehow - destroy car to respawn.
            if (currentState.targetPositions.Length == 0)
            {
                GameLogic.myInstance.DestroyCar(myCarController.myPlayerData, true);
                Debug.LogWarning("Error : Could not find target position for car " + transform.gameObject.name + ". Killing car");
            }

            //Set the waitHandle to make sure that the planner can retrieve a new planning
            waitHandle.Set();

        }
    }