Beispiel #1
0
        protected override void OnOutputReceived(float[] output)
        {
            // output 0 horizontal input - steer
            // output 1 vertical input - accelerate
            float horizontalInput = output[0];
            float verticalInput   = output[1];

            carMovement.Move(verticalInput, horizontalInput, 0.0f);
        }
Beispiel #2
0
 private void FixedUpdate()
 {
     if (isAlive)
     {
         movement.Move();
     }
     else
     {
         movement.Stop();
     }
 }
Beispiel #3
0
    //Calculate path and send move event to car script
    private void GetPath()
    {
        if (Vector3.Distance(transform.position, nextPoint) < poindDestinationDistance)
        {
            (nextPoint, pathID, wayID, pointID, needNewPath) = movePath.GetNextPoint(pathID, wayID, pointID);
            if (needNewPath)
            {
                movePath           = GlobalController.Instance.allPaths[Random.Range(0, GlobalController.Instance.allPaths.Count)];
                pathID             = 0;
                wayID              = 0;
                pointID            = 0;
                needNewPath        = false;
                transform.position = new Vector3(movePath.path[pathID].ways[wayID].points[pointID].position.x, transform.position.y, movePath.path[pathID].ways[wayID].points[pointID].position.z);
                transform.LookAt(movePath.path[pathID].ways[wayID].points[pointID + 1].position);
                rigbody.velocity = Vector3.zero;
                (nextPoint, pathID, wayID, pointID, needNewPath) = movePath.GetNextPoint(pathID, wayID, pointID);
            }
            navigator.CalculatePath(nextPoint, navMeshPath);
        }

        Vector3 dir  = (nextPoint - transform.position).normalized;
        float   dot  = Vector3.Dot(dir, transform.forward);
        float   dot1 = Vector3.Dot(dir, transform.right);

        float footbreak = 0;

        if (CanGoToCrossroad)
        {
            carMovement.brakeInput = 0;
            footbreak = 0;
        }
        else
        {
            carMovement.brakeInput = -1;
            footbreak = -1;
        }

        if (IsOnCrossroad && GetCarTurnPath() != 2)
        {
            carMovement.brakeInput = 0;
            footbreak = 0;
        }

        carMovement.Move(dot, footbreak, dot1);


        //line for path
        for (int i = 0; i < navMeshPath.corners.Length - 1; i++)
        {
            Debug.DrawLine(navMeshPath.corners[i], navMeshPath.corners[i + 1], Color.red);
        }
    }
Beispiel #4
0
 private void FixedUpdate()
 {
     movement.Move();
 }