x


Function variable problem.

Hey!

I have a strange problem with the code below:

The rotateSpeed variable does not affect the speed of rotation. But if I remove the variable from the Update function and just put a number there, the rotation speed is affected. Can anyone see what the problem is?

Cheers!

var rotateSpeed : float = 35;


 // Interpolate from "from" to "to" with a fixed speed (in degrees per second).
function InterpQuaternionTo( from : Quaternion, to : Quaternion, speed : float ) : Quaternion
{
   var dist = Quaternion.Angle(to, from);
   var maxStepSize = speed * Time.deltaTime;

   if (dist > maxStepSize)
   {
       return Quaternion.Lerp( from, to, maxStepSize / dist );
   }
   else
   {
      return to;
   }
}


function Update()
{
       transform.localRotation = InterpQuaternionTo(transform.localRotation, targetOrientation, rotateSpeed);
}
more ▼

asked Jul 07 '10 at 04:54 PM

Jaywalker gravatar image

Jaywalker
514 15 21 30

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

If you do that and put it on a script that's attached to a prefab, the value that it's going to use for your member variable is the one that's stored on the prefab.

If you want it to solely be based on script and not from the prefab data, declare it to be private. Or change it on the prefab.

more ▼

answered Jul 07 '10 at 05:08 PM

Tetrad gravatar image

Tetrad
7.2k 27 37 89

Thanks! big fail on my part there....ill never forget it now though :-)

Jul 07 '10 at 05:43 PM Jaywalker
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5097
x3465
x825
x442

asked: Jul 07 '10 at 04:54 PM

Seen: 1175 times

Last Updated: Jul 07 '10 at 04:54 PM