PDA

View Full Version : Repeat function in an expression


tonyamiga
19-02-2013, 07:07 PM
Hi Guys,
I am trying to write an expression for a project. So far I have the following:
.........................

magnet1.magnitude = 0;
if (gear.rotateY >360)
{
magnet1.magnitude = -20;
}

.........................
As you can see I have an object called magnet1 which I set to magnitude 0 then when the gear object
rotates to one full rotation it triggers the magnet (a Radial force)
This works well, my question is how do I continue the expression to make the magnet trigger
everytime the gear rotates 360 degress ?
Such as a trigger pulse each rotation of the gear.

Thanks Tony

stwert
19-02-2013, 08:35 PM
There's a few ways to approach it. These might not be the most elegant, but depending on the situation, it should work.
1) Reset the gear rotate. If gear.rotateY is 360 or more, set to 0.
or
2) Create a variable or attribute instead of hardcoding 360. If gear.rotateY is greater than the variable (which starts at 360) add 360 to the value you're testing against.