WorldViz User Forum .addAction in loops
 Register FAQ Search Today's Posts Mark Forums Read

#1
08-24-2009, 07:05 PM
 tsmurphy Member Join Date: Aug 2009 Posts: 4

I am trying to do something relatively simple: moving an object at a variable speed. I'm doing this by chopping up the line the object is moving along into intervals, and having each interval (e.g. 1/10th of the entire movement) have a different speed of movement, such that it slows down or speeds up as it moves. This is what I have:

Code:
```
intervals = 10

for index in range(1, intervals):
destination = (startPosition-endPosition) * (index/intervals) + endPosition
speed = destination**2
movePath = vizact.goto([0, destination, 0], speed)
Here's what should happen. The destination of the particular movement interval is calculated. Then speed is set at the square route of the destination (thus the speed will vary). Then the object ("cover", in this case) queues the action to move down that particular interval at the given speed. It should then spin 90 degrees. And so on for the next interval of the line.

Here's what does happen: It uses the last entry of the loop to determine the speed, moves directly to the final destination, and then spins for 10 seconds after all of the movement is complete (rather than alternating movement and spinning for 1 second). Does anyone know what I can do to fix this, or how I could even start?

Last edited by tsmurphy; 08-24-2009 at 07:07 PM. Reason: to correct something obviously
#2
08-25-2009, 09:21 AM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
I believe this is an issue with Python's integer division. When you divide an integer with another integer Python will return the nearest integer to the true value. To get a floating point value you must convert one of the values to a float. Try changing the code:
Code:
`(index/intervals)`
to:
Code:
`(float(index)/intervals)`
#3
08-25-2009, 11:37 AM
 tsmurphy Member Join Date: Aug 2009 Posts: 4
Yeah, that was exactly it. Thank you!

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements Vizard Precision Position Tracker (PPT) Plug-in development

All times are GMT -7. The time now is 09:27 AM.