rotation problem

hi, i have a problem of rotation of pendulum,it will rotate 70 degree right and -70 left, m using GUI slider to adjust speed, but the pendulum is rotating very very slow, m attaching script please help…

1st script(GUIBUTTON)

var speedselection;

speedselection = GUI.HorizontalSlider (Rect (550, 45, 100, 30), speedselection, 0.5, 1.5);

(min_speed=0.5, max_speed=1.5)

2nd script(pendulum_rotation)

var angle : float ;

var x : float ;

x = 0.0f;

var i:int=1;

var speed:float;

var time:float;

function Update ()

{

var guibutton:GUIBUTTON = GameObject.Find(“Scene”).GetComponent(GUIBUTTON);

time=guibutton.speedselection;

speed = 70/time;

angle = Time.deltaTime * speed;

if(x <= 70 i==1)
{
x += angle;
if ( x>69)
{
i =-1;
}
transform.Rotate (0,angle, 0 );

}
else if(x >= -70 i== -1)
{
x -= angle;
if ( x < -69)
{
i =1;
}
transform.Rotate (0,-angle,0);
}
}

m getting this error “transform.localRotation assign attempt for ‘Cube’ is not valid. Input localRotation is { NaN, NaN, NaN, NaN }” in line “transform.rotate(0,angle,0)”

value of x will be NaN in the inspector… i dont knw wht to do next, please help

Can you format your post so that it is easier to read? Use the code tags available if you “Go Advanced” to separate out which is code.

var angle : float ;

var x : float ;

x = 0.0f;

var i:int=1;

var speed:float;

var time:float;

function Update ()

{

var guibutton:GUIBUTTON = GameObject.Find(“Scene”).GetComponent(GUIBUTTON);

time=guibutton.speedselection;

speed = 70/time;

angle = Time.deltaTime * speed;

if(x <= 70 i==1)
{
x += angle;
if ( x>69)
{
i =-1;
}
transform.Rotate (0,angle, 0 );

}
else if(x >= -70 i== -1)
{
x -= angle;
if ( x < -69)
{
i =1;
}
transform.Rotate (0,-angle,0);
}
}

much better :slight_smile:

@The OP: It looks like the tags are still incorrect. You can apply the tags in the editor, or enter them manually by typing [ code ] (without the spaces), pasting the code, and then typing [ /code ] (without the spaces). You should then get something like this:

function foo()
{
}

(Another tip: Replacing all hard tabs with spaces before pasting in code will increase the chances of the formatting being preserved correctly.)