Rotation stops when reach the limit.

I have a script of an helicopter and, when Main rotors reach the max speed, they stop to spin. how to solve that?

it’s like this:

var rotation = 0;
var speed = 0;
var maxspeed = 20000;

function Update (){
    rotation += 0.001 * Time.deltaTime;
    speed += rotation * 15;
    
    if(speed > maxspeed){
        speed = maxspeed;
    }
}

thx any advance.

I’m also interested in where you actually rotate the object?

Anyway, i guess your problem is that you use int variables! All say Unityscript (Javascript) is easier, but that’s one of the pitfalls :wink:

You didn’t specify a variable type so the type is determined via type-inference. Since you initialize your variables with integer values (0 and 20000) they become int variables. You need float variable so you can store fractional numbers. You can either give your variables a type manually:

var rotation : float = 0;
var speed : float = 0;
var maxspeed : float = 20000;

or initialize the variables with floats:

var rotation = 0.0;
var speed = 0.0;
var maxspeed = 20000.0;

It looks like all you need is something like this.

if(speed >= maxspeed) //>= is greater than or equal to
{
  speed = 0;
}

And handle the rotation as you normally would. All you need is to tell it to “stop” when it reaches the max speed.

Or do you need something more than this? I didn’t exactly understand your question perfectly.

thank you guys! I’ll really think about it! thx

This is a script you can use, i dont know if it work i dont tested it yet
Just name this script : HelicopterRotation.cs
Here the script :
CLICK TO GET THE SCRIPT