Tap Handle Translating Too Fast

We’re busy building a simulation that will be used in facilitated school and community workshops to show various African communities how to replace washers in different types of taps. Massive amounts of water are lost through worn out washers that are not replaced.

We are currently working on a scene that includes a bib tap cutaway. We have two problems that we’re unable to sort out. Firstly, when you click on the handle it moves up and down too fast. Secondly,we want the handle to rotate clockwise on the first click and then anti-clockwise on the second click, i.e. to close. Here is the script that is connected to the handle. Most of the commented out code is what we’ve tried so far. I’d be grateful for some help:

private var waterRun : GameObject;
private var man : GameObject;

var other : UVScroller;
var checkSum : int = 0;
var handle2 : GameObject;
var speed = 0.01;

handle2 = GameObject.Find("Handle_Washer_Grp");
waterRun = GameObject.Find("Tap_anim");
man = GameObject.Find("Man4");

private var rotateTo : Quaternion; 

function Start(){ 
rotateTo = transform.rotation; 
} 

[color=red]function OnMouseDown () {

	//checkSum = 1;
	//Debug.Log (checkSum);

	if (checkSum == 0){
			waterRun.animation["Take 001"].normalizedTime = 0.01;
			//Time.timeScale = 0.5;
			handle2.transform.Translate(0, 0, 0.05);
			//handle2.transform.position = Vector3(37.7238, 7.6, 42.56981);
			//handle2.transform.Translate(Time.deltaTime,0,0,0.05);
			//handle2.transform.Translate((Time.deltaTime * 100) * 0, 0, 0.05);
			//var translation = Time.deltaTime * Time.timeScale * 0.0001;
			//handle2.transform.Translate (0, 0, translation);[/color]
			waterRun.animation.Play();
			man.animation.Play();
			waterRun.animation["Take 001"].speed = 1;

			var flow1 = GameObject.Find("outlet_a");
			var rate1 = flow1.GetComponentInChildren(UVScroller);
			rate1.startFlow();
			
			var flow2 = GameObject.Find("outlet_b");
			var rate2 = flow2.GetComponentInChildren(UVScroller);
			rate2.startFlow();
			
			var flow3 = GameObject.Find("Water_Inlet");
			var rate3 = flow3.GetComponentInChildren(UVScroller);
			rate3.startFlow();		
			checkSum = 1;
			
				} else if (checkSum == 1){
				waterRun.animation["Take 001"].normalizedTime = 1; 	 	
				waterRun.animation["Take 001"].speed = -1;
				man.animation.Stop();				
				handle2.transform.Rotate(0, 0, 120);
				handle2.transform.Translate(0, 0 , -0.05);

				
				var flow4 = GameObject.Find("outlet_a");
				var rate4 = flow4.GetComponentInChildren(UVScroller);
				rate4.stopFlow();
			
				var flow5 = GameObject.Find("outlet_b");			
				var rate5 = flow5.GetComponentInChildren(UVScroller);
				rate5.stopFlow();
				
				var flow6 = GameObject.Find("Water_Inlet");
				var rate6 = flow6.GetComponentInChildren(UVScroller);
				rate6.stopFlow();

				checkSum = 0;	
					}				
				} 		
function Update(){

   if(Input.anyKeyDown ){ 
			rotateTo = transform.rotation * Quaternion.Euler( 0, 0, 90 ); 
			} 
				if(Quaternion.Angle(transform.rotation, rotateTo) > 0.5){ 
					transform.Rotate(Vector3.forward, 90 * Time.deltaTime); 
					} 
		else if(transform.rotation != rotateTo){ 
			transform.rotation = rotateTo; 
			} 
		}

Post your startFlow function.

As for your second question, define a velocity of rotation and change its value after every rotation

var rotVel : float = 90;

...


function Update(){

   if(Input.anyKeyDown ){
         rotateTo = transform.rotation * Quaternion.Euler( 0, 0, rotVel );
         }
            if(Quaternion.Angle(transform.rotation, rotateTo) > 0.5){
               transform.Rotate(Vector3.forward, rotVel * Time.deltaTime);

               rotVel *= (-1);

               }
      else if(transform.rotation != rotateTo){
         transform.rotation = rotateTo;
         }
      }

Thanks Dart! The startFlow()function is part of the UVScroller script.

/ Scroll main texture based on time
//Gradually slow down water
var Speed = 0; 
var minSpeed : float= 0; 
var maxSpeed : float = 150; 
var Accel : float = 3; 
var decel : float = 0.1; 
var CurrentScrollSpeed : float;
CurrentScrollSpeed = 0.001;


function Update () 
{
    var offset = Time.time * CurrentScrollSpeed;
    renderer.material.SetTextureOffset ("_BumpMap", Vector2(offset/-7.0, offset));
    renderer.material.SetTextureOffset ("_MainTex", Vector2(offset/10.0, offset));
}

function startFlow()
{
CurrentScrollSpeed = Accel + Mathf.Clamp(Speed, minSpeed, maxSpeed - Accel); 

}

function stopFlow()
{
CurrentScrollSpeed = -Accel + Mathf.Clamp(Speed, minSpeed +Accel, maxSpeed ); 

}

I’ve tried your code and it rotates in both directions but still too fast! It jumps to the position at once. How do I slow down the rotation?