... How to rotate something around its axis...

Oh jeez. I never thought I’d be asking questions like this again! Guess its been a little too long since I used Unity. >_< Anyways. I have some fans that I want to rotate around their X axis, but I can’t remember the right script and all the things I try give me errors. Thanks for putting up with me. ;D

-Moldorma

EDIT: Figured it out, but how would I make the rotation start out slow and speed up, then when I release the key start slowing down the rotation. Thanks!

I believe Transform.Rotate would provide you with what you are looking to do.

http://unity3d.com/Documentation/ScriptReference/Transform.Rotate.html

HTH,

– Clint

Right, I got that part already, but how would I speed up and slow down the rotation the way AddForce speeds up while it happens and then slows down.

var fanspeed = 0;

function Update () {
	if (fanspeed < 0) {
		fanspeed = 0;
	}
	if (Input.GetKey("up")) {
		fanspeed += 0.5;
		transform.Rotate (0, 0, -fanspeed);
	}else{
		fanspeed -= 0.2;
	}
}

Doesn’t seem to work. :stuck_out_tongue:

If you’re using physics, I’d recommend a Euler rotation motor. No scripting involved!

Otherwise…

var fanspeed : float = 0.0; //yours was being initialized to an int, which was problem #1

function Update () { 
   if (Input.GetKey("up")) { 
      fanspeed += 0.5; 
   }else{ 
      fanspeed -= 0.2; 
   } 
   fanspeed = Mathf.Clamp(fanspeed, 0.0, 200.0); //change 200 to whatever max speed you want them to be set to
   transform.Rotate (0, 0, -fanspeed); //it was also only being rotated while the key was held down. this line needs to be outside the if statement completely
}

Well, I couldn’t figure out the Euler Motor, but your code did the trick anyways. Thanks for the help. :wink: