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

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoatController : BuoyantObject {
public float trunSpeed = 0.5f;
public float breakSpeed = 20f;
// Use this for initialization
void Start() {
}
void Update() {
lookAtDir(Vector3.ProjectOnPlane(rb.velocity, Vector3.up));
}
// Update is called once per frame
void lookAtDir(Vector3 inputDir) {
Quaternion targetRotation = Quaternion.LookRotation(inputDir, Vector3.up);
float str = Mathf.Min(trunSpeed * Time.deltaTime, 1);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, str);
}
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.CompareTag("Rock")) {
float forwardHitSpeed = Vector3.Project(collision.relativeVelocity, transform.forward).magnitude;
Debug.Log("Forward hit:" + forwardHitSpeed);
if (forwardHitSpeed > breakSpeed) {
NotificationServer.notify("show GameOverPanel");
}
}
}
}