I have programmed my boat to move, and it happily sails around, but it can go through the islands I have made out of the terrain. I have put a box collider around it, but that didn’t help. If my code needs to be changed, please tell me. This is my code:
var rock_isGoingToRight = true;
var rock_Amount = 0;
var isRockingBackwards = true;
var isCollided = false;
function Update()
{
if((Input.GetKey("up") || Input.GetKey("w")) && isCollided === false) {
transform.Translate(Vector3.right * (Time.deltaTime*40));
}
if(Input.GetKey("right") || Input.GetKey("d")) {
transform.Rotate(Vector3.forward * (Time.deltaTime*10));
}
if(Input.GetKey("left") || Input.GetKey("a")) {
transform.Rotate(Vector3.back * (Time.deltaTime*10));
}
if(rock_isGoingToRight === true) {
transform.Rotate(Vector3.right * Time.deltaTime);
rock_Amount++;
if(rock_Amount > 90) {
rock_isGoingToRight = false;
}
} else {
transform.Rotate(Vector3.left * Time.deltaTime);
rock_Amount--;
if(rock_Amount < -90) {
rock_isGoingToRight = true;
}
}
}
function OnCollisionEnter(theCollision : Collision) {
isCollided = true;
}
if your boat is a mesh object use a mesh collider and attach the boat object to the mesh field.
– zer0c00l42066I agree with the terrain and mesh collider solution
– GeoBlazer