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.

41 lines
1.1 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class BoatController : BuoyantObject {
  6. public float trunSpeed = 0.5f;
  7. public float breakSpeed = 20f;
  8. // Use this for initialization
  9. void Start() {
  10. }
  11. void Update() {
  12. lookAtDir(Vector3.ProjectOnPlane(rb.velocity, Vector3.up));
  13. }
  14. // Update is called once per frame
  15. void lookAtDir(Vector3 inputDir) {
  16. Quaternion targetRotation = Quaternion.LookRotation(inputDir, Vector3.up);
  17. float str = Mathf.Min(trunSpeed * Time.deltaTime, 1);
  18. transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, str);
  19. }
  20. void OnCollisionEnter(Collision collision) {
  21. if (collision.gameObject.CompareTag("Rock")) {
  22. float forwardHitSpeed = Vector3.Project(collision.relativeVelocity, transform.forward).magnitude;
  23. Debug.Log("Forward hit:" + forwardHitSpeed);
  24. if (forwardHitSpeed > breakSpeed) {
  25. NotificationServer.notify("show GameOverPanel");
  26. }
  27. }
  28. }
  29. }