You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.5 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. public class trailer : MonoBehaviour {
  4. public float rotationLimit;
  5. public GameObject trailerHook;
  6. public GameObject rotationMimick;
  7. private Rigidbody rb;
  8. public Vector3 centreOfMass;
  9. //private Rigidbody carRb;
  10. // Use this for initialization
  11. void Start () {
  12. rb = GetComponent<Rigidbody> ();
  13. rb.centerOfMass = centreOfMass;
  14. Component[] carColliders = transform.root.GetComponentsInChildren<Collider> ();
  15. foreach (Collider carCol in carColliders){
  16. foreach (Collider carCol2 in carColliders){
  17. if (carCol.enabled && carCol2.enabled)
  18. Physics.IgnoreCollision(carCol, carCol2);
  19. }
  20. }
  21. }
  22. // Update is called once per frame
  23. void Update () {
  24. }
  25. void FixedUpdate(){
  26. transform.position = trailerHook.transform.position;
  27. //rb.MovePosition (trailerHook.transform.position);
  28. Vector3 newRot = transform.rotation.eulerAngles;
  29. //newRot.y = rotationMimick.transform.rotation.eulerAngles.y;
  30. //newRot.x = ClampAngle (newRot.x, -10, 10);
  31. //newRot.z = ClampAngle (newRot.z, -15, 15);
  32. //Debug.Log ("Trailer rot: " + newRot);
  33. //rb.MoveRotation (Quaternion.Euler (newRot));
  34. transform.LookAt (rotationMimick.transform.position);
  35. }
  36. private static float ClampAngle (float angle, float min, float max) {
  37. if (max < -360)
  38. max += 360;
  39. if (max > 360)
  40. max -= 360;
  41. if (min < -360)
  42. min += 360;
  43. if (min > 360)
  44. min -= 360;
  45. if (angle < -360)
  46. angle += 360;
  47. if (angle > 360)
  48. angle -= 360;
  49. return Mathf.Clamp (angle, min, max);
  50. }
  51. }