View Single Post
  #4  
Old 01-06-2014, 07:17 AM
Erikvdb Erikvdb is offline
Member
 
Join Date: May 2013
Posts: 63
Frank, that only starts/stops the spinning, it doesn't ease-in or out.

I think a more flexible solution would be to wire -in 3ds max terms- the wheel rotation to the car translation. I can't really remember how it works best exactly, but here's a quick and dirty version, based on Frank's code:

Code:
import viz
import vizact
import vizmat

viz.go()

car1 = viz.add('box.wrl')
carPos = car1.getPosition()

viz.eyeheight(0)
viz.MainView.setPosition(-5,0,-20)

action1 = vizact.moveTo([-10,0,0],speed=4.00, interpolate=vizact.easeInOut)

def actionTime():
	car1.addAction(action1,0)
	
def onUpdate():
	global carPos
	newPos = car1.getPosition()
	distance = vizmat.Distance(carPos,newPos)
	rotation = distance * viz.getFrameElapsed() * 2000 
	car1.setEuler([0,0,rotation],viz.REL_LOCAL)
	carPos = newPos
	
vizact.onkeydown(' ', actionTime)
vizact.onupdate(0, onUpdate)
The 2000 number should be based on the wheel circumference, but I forgot how it relates exactly, so it's just an arbitrary multiplier.
Reply With Quote