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.

51 lines
1.1 KiB

8 years ago
8 years ago
  1. using UnityEngine;
  2. using System.Collections;
  3. public class fence : MonoBehaviour {
  4. private Rigidbody rigidbody;
  5. // Use this for initialization
  6. void Start () {
  7. rigidbody = GetComponent<Rigidbody> ();
  8. }
  9. // Update is called once per frame
  10. void Update () {
  11. }
  12. void OnCollisionEnter(Collision collision) {
  13. if (collision.transform.tag == "moveable") {
  14. rigidbody.isKinematic = false;
  15. rigidbody.velocity = collision.relativeVelocity;
  16. /*
  17. ContactPoint contact = collision.contacts[0];
  18. Vector3 push = transform.position - contact.point;
  19. push.Normalize();
  20. Debug.Log("fence: " + push);
  21. rigidbody.AddForceAtPosition(push*1000, contact.point);
  22. */
  23. }
  24. }
  25. void OnTriggerEnter(Collider other) {
  26. if (other.transform.tag == "moveable") {
  27. rigidbody.isKinematic = false;
  28. //rigidbody.velocity = other.relativeVelocity;
  29. /*
  30. ContactPoint contact = collision.contacts[0];
  31. Vector3 push = transform.position - contact.point;
  32. push.Normalize();
  33. Debug.Log("fence: " + push);
  34. rigidbody.AddForceAtPosition(push*1000, contact.point);
  35. */
  36. }
  37. }
  38. }