I want to rotate my boat when it reaches certain point (Point B) so that it can turn backwards to Point A or starting point. The script that I have is the boat doesn't rotate when it reaches point B, it just move backwards without rotating. I created a cube as my Point B, and attached it to the script of the boat. Another question is how could I control the speed of rotation?.
This is the boat script:
var pointB : Transform;
private var pointA : Vector3;
var speed = 1.0;
var rotateup = true;
function Start () {
pointA = transform.position;
while (true) {
var i = Mathf.PingPong(Time.time * speed, 1);
transform.position = Vector3.Lerp(pointA, pointB.position, i);
yield;
}
}
function Update () {
if (rotateup){
for (t = 0.0; t <= 5.0; t += Time.deltaTime){
transform.Rotate(0.1*Time.deltaTime,0,0);
transform.Rotate(0,0,0.1*Time.deltaTime);
}
rotateup = false;
return;
}
if (!rotateup){
for (t = 0.0; t <= 5.0; t += Time.deltaTime){
transform.Rotate(-0.1*Time.deltaTime,0,0);
transform.Rotate(0,0,-0.1*Time.deltaTime);
}
rotateup = true;
return;
}
}