The code for turning car going from down side(called south)
- using System;
- using UnityEngine;
- [RequireComponent(typeof(MoveCar))]
- public class NorthTurnRight : MonoBehaviour
- {
- private Rigidbody rb;
- private float eulerAngleVelocity;
- private void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- private void FixedUpdate()
- {
- rightTurn();
- }
- private void OnEnable()
- {
- transform.GetChild(0).gameObject.SetActive(true);
- }
- void rightTurn()
- {
- float carRotation = Mathf.Floor(transform.eulerAngles.y);
- if(transform.localPosition.x > -20.5f && carRotation != 180f)
- {
- if(carRotation >= -176f && carRotation <= 184f)
- {
- transform.localRotation = Quaternion.Euler(new Vector3(0, 180f, 0));
- return;
- }
- eulerAngleVelocity = GetComponent<MoveCar>().speed *8.57f;
- Quaternion deltaRotation = Quaternion.Euler(new Vector3(0, eulerAngleVelocity, 0) * Time.fixedDeltaTime);
- rb.MoveRotation(rb.rotation * deltaRotation);
- }
- }
- }
The code for turning car going from upside(called north)
Then moving to a problem:
https://vimeo.com/535931682
Talking to a code the car must turn (south one) from 90 to 180 degrees, but it reverses. Working cars are using the same type of script, but they don't have any problems. What is the problem?