Suspension.cs 835 B

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using UnityEngine;
  3. namespace UnityStandardAssets.Vehicles.Car
  4. {
  5. // this script is specific to the car supplied in the the assets
  6. // it controls the suspension hub to make it move with the wheel are it goes over bumps
  7. public class Suspension : MonoBehaviour
  8. {
  9. public GameObject wheel; // The wheel that the script needs to referencing to get the postion for the suspension
  10. private Vector3 m_TargetOriginalPosition;
  11. private Vector3 m_Origin;
  12. private void Start()
  13. {
  14. m_TargetOriginalPosition = wheel.transform.localPosition;
  15. m_Origin = transform.localPosition;
  16. }
  17. private void Update()
  18. {
  19. transform.localPosition = m_Origin + (wheel.transform.localPosition - m_TargetOriginalPosition);
  20. }
  21. }
  22. }