Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit forward           = controller.CastRayCast(new Vector3(0, 0, 1), wallLayer);
        RaycastHit farLeft           = controller.CastRayCast(new Vector3(-1, 0, 0), wallLayer);
        RaycastHit farRight          = controller.CastRayCast(new Vector3(1, 0, 0), wallLayer);
        RaycastHit closeRight        = controller.CastRayCast(new Vector3(0.5f, 0, 1), wallLayer);
        RaycastHit closeLeft         = controller.CastRayCast(new Vector3(-0.5f, 0, 1), wallLayer);
        RaycastHit checkpointForward = controller.CastRayCast(new Vector3(0, 0, 1), checkpointLayer);
        RaycastHit checkpointRight   = controller.CastRayCast(new Vector3(0.25f, 0, 1), checkpointLayer);
        RaycastHit checkpointLeft    = controller.CastRayCast(new Vector3(-0.25f, 0, 1), checkpointLayer);


        if (forward.distance < 25)
        {
            Debug.Log("obstacle");
            if (farRight.distance > farLeft.distance)
            {
                controller.Rotate(1.5f);
                controller.Move(0.5f);
                speed = 0.5f;
                Debug.Log("turn right");
            }
            else
            {
                controller.Rotate(-1.5f);
                controller.Move(0.5f);
                speed = 0.5f;
                Debug.Log("turn left");
            }
            if (farRight.distance == farLeft.distance && closeLeft.distance < closeRight.distance)
            {
                controller.Rotate(-0.25f);
            }
            if (farRight.distance == farLeft.distance && closeLeft.distance > closeRight.distance)
            {
                controller.Rotate(0.25f);
            }
        }
        else
        {
            controller.Move(1.25f);
            speed = 1.25f;
            controller.Rotate(0);
        }
        if (closeLeft.distance < 2f || farLeft.distance < 1.5f)
        {
            controller.Rotate(0.2f);
            Debug.Log("avoid");
        }
        if (closeRight.distance < 2f || farRight.distance < 1.5f)
        {
            controller.Rotate(-0.2f);
            Debug.Log("avoid");
        }
    }
Ejemplo n.º 2
0
    private void Move()
    {
        RaycastHit frontWall       = tank.CastRayCast(Vector3.forward, wallLayer);
        RaycastHit frontCheckPoint = tank.CastRayCast(new Vector3(0, 0, 1), checkpointLayer);
        RaycastHit backCheckPoint  = tank.CastRayCast(new Vector3(0, 0, -1), checkpointLayer);

        if (passed.Contains(frontCheckPoint.collider))
        {
            maxRotation = 90;
            FindRotateDirection(true);
            startRotation  = tank.GetRotation();
            turning        = true;
            turningToFront = true;
        }
        else if (!passed.Contains(backCheckPoint.collider) && backCheckPoint.distance < 5)
        {
            if (currentCheckPoint.transform == backCheckPoint.transform)
            {
                passed.Add(backCheckPoint.collider);
            }

            currentCheckPoint = frontCheckPoint;
        }

        if (frontWall.distance < 18)
        {
            if (frontWall.distance < 1f)
            {
                FindRotateDirection(false);
            }
            else
            {
                FindRotateDirection(true);
            }

            maxRotation   = 45;
            startRotation = tank.GetRotation();
            turning       = true;
        }
        else
        {
            tank.Move(moveSpeed);
        }
    }
    // Update is called once per frame
    void Update()
    {
        // Figure out speed
        TankController.Move(TankController.CastRayCast(front, wall).distance / 27.5f);

        // Figure out the rotations.
        if (TankController.CastRayCast(frontLeft, wall).distance > TankController.CastRayCast(frontRight, wall).distance)
        {
            TankController.Rotate(-0.5f);
            // Debug.Log("Should I go Left?");
        }
        if (TankController.CastRayCast(frontLeft, wall).distance < TankController.CastRayCast(frontRight, wall).distance)
        {
            TankController.Rotate(0.5f);
            // Debug.Log("Should I go right?");
        }

        //Figure out where to shoot
        if (TankController.CastRayCast(Tuner, wall).distance > 0)
        {
            Debug.Log("hey I hit something!");
        }
    }