Example #1
0
    public void OnPointerDownDelegate(PointerEventData data)
    {
        if (carController == null)
        {
            carController = grpInputs.carController;
        }

        if (btn_Left)
        {
            carController.Btn_LeftActivate();
        }
        if (btn_Right)
        {
            carController.Btn_RightActivate();
        }
        if (btn_Accelerate)
        {
            carController.Btn_AccelerationActivate();
        }
        if (btn_Break)
        {
            carController.Btn_BreakActivate();
        }
        if (btn_Respawn)
        {
            carController.Btn_Respawn();
        }
    }
Example #2
0
// -- > Turn car to the left or to the right if needed
    public void TurnLeftAndRight()
    {
        Vector3 PosCenter = carController.frontCapsuleCollider.gameObject.transform.position;

        Vector3 dir = Target.transform.position - PosCenter;                                                                            // Angle between car and target

        angle = Vector2.Angle(new Vector2(dir.x, dir.z),                                                                                // Find angle between car the target path
                              new Vector2(transform.forward.x, transform.forward.z));
        float angle2 = AngleDir(transform.forward, dir, transform.up);                                                                  // Find if car is on the left or on the right of the target path


        //Debug.DrawLine(PosCenter,PosCenter + dir,Color.yellow);
        float percentageAIRotation = (angle - 0) / (15F - 0);

        //Debug.Log ("angle : " + angle);
        if (!b_contactWithOtherCar)
        {
            if (!b_DisableRotation)
            {
                if (Obstacles == "Null")
                {
                    if (angle2 == 1 && Mathf.Abs(angle) > 2)                                                                                                            // Check if the car need to turn left or right
                    {
                        carController.Btn_RightActivate();
                        carController.Btn_LeftDeactivate();
                        //Debug.Log ("Turn_Right");
                    }
                    else if (angle2 == -1 && Mathf.Abs(angle) > 2)
                    {
                        carController.Btn_RightDeactivate();
                        carController.Btn_LeftActivate();
                        //Debug.Log ("Turn_Left");
                    }
                    else
                    {
                        carController.Btn_RightDeactivate();
                        carController.Btn_LeftDeactivate();
                        //Debug.Log ("Go_Forward");
                    }
                }
                else if (Obstacles == "Left")
                {
                    //Debug.Log("Obstacle Middle");
                    carController.Btn_RightActivate();
                    carController.Btn_LeftDeactivate();                     //}
                }
                else if (Obstacles == "Right")
                {
                    //Debug.Log("Obstacle Middle");
                    carController.Btn_LeftActivate();
                    carController.Btn_RightDeactivate();                     //}
                }
            }
            else                                                                                                                                                                                        // Car go backward because she can't move
            {
                if (Obstacles == "Right")
                {
                    carController.Btn_RightActivate();
                    carController.Btn_LeftDeactivate();
                }
                else
                {
                    carController.Btn_RightDeactivate();
                    carController.Btn_LeftActivate();
                }

                percentageAIRotation = (30 - 0) / (15F - 0);
            }



            if (Obstacles == "Null")
            {
                smoothAvoid = Mathf.MoveTowards(smoothAvoid, 1, Time.deltaTime * .5f);
                carController.eulerAngleVelocity.y                                                                                                                              // Car turn left and right
                    = (CarAIEulerRotation + offsetRandomEulerAngle) * percentageAIRotation * smoothAvoid;
            }
            else
            {
                smoothAvoid = 0;


                carController.eulerAngleVelocity.y                                                                                                                              // Car turn left and right
                    = (CarAIEulerRotation + offsetRandomEulerAngle) /* * percentageAIRotation */ * 9f * curveOvaidObstacle.Evaluate(1 - (ObstacleDistance * 1) / raycastLength);
            }
        }
    }