I am currently scripting a boat. I am using a box collider on the water, and a rigidbody on the boat so it looks like it’s floating. There’s also a Terrain collider on the terrain. I want my boat to stop when it hits the terrain, but right now I can’t even get Unity to correctly detect that the boat has hit the terrain. Here’s my code:
var speed : float = 5.0;
var rotateSpeed : float = 1.0;
function Update ()
{
//Move the boat forward
if(Input.GetKey(KeyCode.W))
{
transform.Translate(Vector3(1 * speed *Time.deltaTime, 0, 0));
}
// Rotate the boat
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
//Plays Animation on the rod
if(Input.GetKeyDown('space'))
{
var rod = transform.Find("Pole (4)");
rod.animation.Play('Take 001');
}
}
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag == "Terrain")
{
Debug.Log("Hit");
}
}