Hi, I am trying to add a sort of falloff to my movement and this is a piece of it's code:
var moveSpeed = 6;
for(x=moveSpeed;x>=0;x--)
This code seems to be executing all at once(or too fast) and the GameObject is moving 21 units instead of 6, then 5, then 4, down to 0. How could I recode this so that there is a seemingly gradual deduction, or possibly at decimal values so its smooth?
The problem with your code is that there's no reference to any type of external time variable, so it's going to execute as quickly as your computer can calculate it - which is very fast...
If you really want it executing in a loop, the way to do it is:
var moveSpeed : float;
var moveDistance : float;
for (x = moveDistance; x < 0; x -= moveSpeed * Time.deltaTime){
yield;
}
Also, if you want a falloff that's not really a very good way of doing it.
Were you using the for loop as a way to compute for your "falloff"? If so, you could also try putting the calculation in your Update() function instead:
moveSpeed -= Time.deltaTime * [some constant/variable for dampening];
This way, the calculation would not entirely be dependent on how fast the cpu can execute your loop.
If you really wanted it in a loop then chief1234's answer is the way to go.