|
|
- using UnityEngine;
- using System.Collections;
-
- public class trailer : MonoBehaviour {
-
- public float rotationLimit;
-
- public GameObject trailerHook;
- public GameObject rotationMimick;
-
- private Rigidbody rb;
- public Vector3 centreOfMass;
- //private Rigidbody carRb;
- // Use this for initialization
- void Start () {
- rb = GetComponent<Rigidbody> ();
- rb.centerOfMass = centreOfMass;
-
- Component[] carColliders = transform.root.GetComponentsInChildren<Collider> ();
-
- foreach (Collider carCol in carColliders){
- foreach (Collider carCol2 in carColliders){
- if (carCol.enabled && carCol2.enabled)
- Physics.IgnoreCollision(carCol, carCol2);
- }
- }
-
- }
-
- // Update is called once per frame
- void Update () {
-
- }
-
- void FixedUpdate(){
- transform.position = trailerHook.transform.position;
- //rb.MovePosition (trailerHook.transform.position);
-
- Vector3 newRot = transform.rotation.eulerAngles;
- //newRot.y = rotationMimick.transform.rotation.eulerAngles.y;
-
- //newRot.x = ClampAngle (newRot.x, -10, 10);
- //newRot.z = ClampAngle (newRot.z, -15, 15);
- //Debug.Log ("Trailer rot: " + newRot);
- //rb.MoveRotation (Quaternion.Euler (newRot));
-
- transform.LookAt (rotationMimick.transform.position);
-
-
-
- }
-
- private static float ClampAngle (float angle, float min, float max) {
-
- if (max < -360)
- max += 360;
- if (max > 360)
- max -= 360;
-
- if (min < -360)
- min += 360;
- if (min > 360)
- min -= 360;
-
- if (angle < -360)
- angle += 360;
- if (angle > 360)
- angle -= 360;
- return Mathf.Clamp (angle, min, max);
- }
-
-
- }
|