WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   .addAction in loops (https://forum.worldviz.com/showthread.php?t=2224)

tsmurphy 08-24-2009 07:05 PM

.addAction in loops
 
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)
    cover.addAction(movePath)
    cover.addAction(vizact.spin(0,1,0,90,1))

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?

farshizzo 08-25-2009 09:21 AM

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)

tsmurphy 08-25-2009 11:37 AM

Yeah, that was exactly it. Thank you!


All times are GMT -7. The time now is 08:56 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC