Scott Ayers
09-11-2010, 06:51 PM
Hey guys.
I'm sure I'm probably missing something simple here.
But in coffee I can incrementally move an object with a bunch of different methods. One of them being with while loops like this: main(doc,op)
{
var c = doc->FindObject("Cube");
var cpos = c->GetRelPos();
var offset = 1;
while(cpos.y < 200)
{
c->SetRelPos(vector(cpos.x, cpos.y + offset, cpos.z));
if (cpos.y < 200) break; //Important!! loops must have a way out to avoid infinite looping
}
if(cpos.y > 200)c->SetRelPos(vector(cpos.x, cpos.y, cpos.z));// set object to 200 if loop positioning overshoots 200
}
This works well and allows me to control the speed of the moving object.
However when I try to do the same thing with Python like this: import c4d
def main():
obj = doc.SearchObject("Cube")
pos = obj.GetRelPos()
offset = 1
while (pos.y < 200):
pos.y = pos.y + offset
if pos.y >= 200: break
obj.SetRelPos(c4d.Vector(pos.x, pos.y,pos.z))
The object moves very abruptly. No matter what I set the offset value to.
Even if I enable the python tag's "Frame Dependent" option.:sad:
I know there are ways to incrementally move things in python by using the += without using a while loop. I've used that method successfully.
But I was wondering why python treats my while loops differently than coffee does?
-ScottA
I'm sure I'm probably missing something simple here.
But in coffee I can incrementally move an object with a bunch of different methods. One of them being with while loops like this: main(doc,op)
{
var c = doc->FindObject("Cube");
var cpos = c->GetRelPos();
var offset = 1;
while(cpos.y < 200)
{
c->SetRelPos(vector(cpos.x, cpos.y + offset, cpos.z));
if (cpos.y < 200) break; //Important!! loops must have a way out to avoid infinite looping
}
if(cpos.y > 200)c->SetRelPos(vector(cpos.x, cpos.y, cpos.z));// set object to 200 if loop positioning overshoots 200
}
This works well and allows me to control the speed of the moving object.
However when I try to do the same thing with Python like this: import c4d
def main():
obj = doc.SearchObject("Cube")
pos = obj.GetRelPos()
offset = 1
while (pos.y < 200):
pos.y = pos.y + offset
if pos.y >= 200: break
obj.SetRelPos(c4d.Vector(pos.x, pos.y,pos.z))
The object moves very abruptly. No matter what I set the offset value to.
Even if I enable the python tag's "Frame Dependent" option.:sad:
I know there are ways to incrementally move things in python by using the += without using a while loop. I've used that method successfully.
But I was wondering why python treats my while loops differently than coffee does?
-ScottA
