WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-24-2009, 07:05 PM
tsmurphy tsmurphy is offline
Member
 
Join Date: Aug 2009
Posts: 4
.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?

Last edited by tsmurphy; 08-24-2009 at 07:07 PM. Reason: to correct something obviously
Reply With Quote
  #2  
Old 08-25-2009, 09:21 AM
farshizzo farshizzo is offline
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)
Reply With Quote
  #3  
Old 08-25-2009, 11:37 AM
tsmurphy tsmurphy is offline
Member
 
Join Date: Aug 2009
Posts: 4
Yeah, that was exactly it. Thank you!
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 Jump


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


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