Notifications
Clear all

[Closed] please help auto rotate

if u have a script for that , that would be amazing !! :bounce:

i am really thankful for your help , i learned allot from your scripting
never the less the problem remains …
ill see if i can pick it up from here as soon as i get a chance

thanks again :bowdown:

ok Denis
thanks again for the help
one idea i had to solve the problem is to have 2 systems
one for linear motion ( your code )
and another for turning
so i added another set of wheels , parented them to the ones with the linear motion code
and wired them to the rotation of the chair

that way the first set of wheels is acting as a “linear motion rotation controller” for the
final wheels , that turn the correct way when the chair turns.
and because they are parented to the first set then the rotation is added to the first value
coming from the first code.

do you think its a reasonable solution ?
code:

with redraw off
(
	delete objects

	rotAttr = attributes "rotAttr"
	(
		parameters main 
		(
			timeAngle type:#point3 animatable:off
		)
	)

	fn makeWheel name: radius: pos: wirecolor: = 
	(
		w = cylinder name:name sides:24 segments:1 radius:radius height:3 slice:on sliceFrom:350 sliceTo:10 pos:pos wirecolor:wirecolor
		w.objectOffsetRot = eulerangles 0 90 0
		CenterObject w
		w
	)
		
	body = 
	(
		b =  (box name:"Wheel_chair" width:20 length:25 height:25 pos:[0,-5,17] wirecolor:blue) - (c = box width:25 length:30 height:25 pos:[0,0,25])
		delete c
		b
	)

	in body
	(
		w1 = makeWheel name:"LF_wheel" radius:5 pos:[-10,10,5] wirecolor:red
		w2 = makeWheel name:"RF_wheel" radius:5 pos:[10,10,5] wirecolor:red
		w3 = makeWheel name:"LR_wheel" radius:15 pos:[-13,-10,15] wirecolor:orange
		w4 = makeWheel name:"RR_wheel" radius:15 pos:[13,-10,15] wirecolor:orange
		w5 = makeWheel name:"LR_wheel_2nd" radius:15 pos:[-17,-10,15] wirecolor:brown
		w6 = makeWheel name:"RR_wheel_2nd" radius:15 pos:[17,-10,15] wirecolor:brown
	)	
	mapped fn makeScript node body ss =
	(
		c = node[#transform][#rotation][1].controller = float_script()
		custattributes.add c rotAttr
		c.addconstant "radius" node.radius
		c.addnode "body" body
		c.addtarget "p0" body[#transform][#position] offset:0
		c.addtarget "p1" body[#transform][#position] offset:1
		c.setexpression ss
		c
	)
	
	ss  = "sign = if dot (p1 - p0) body.transform[2] > 0 then -1 else 1
" 
	ss += "a = this.timeAngle[2] + degtorad(180*(distance [p0.x,p0.y] [p1.x,p1.y])*(f-this.timeAngle[1])*sign/(pi*radius))
"
	ss += "this.timeAngle = [f,a,0]
"
	ss += "a
"

	makeScript body.children body ss
	$LR_wheel_2nd.rotation.controller.X_Rotation.controller = bezier_float ()
	$RR_wheel_2nd.rotation.controller.X_Rotation.controller = bezier_float ()
	$LR_wheel_2nd.parent = $LR_wheel
	$RR_wheel_2nd.parent = $RR_wheel
	paramWire.connect $Wheel_chair.rotation.controller[#Z_Rotation] $LR_wheel_2nd.rotation.controller[#X_Rotation] "Z_Rotation"
	paramWire.connect $Wheel_chair.rotation.controller[#Z_Rotation] $RR_wheel_2nd.rotation.controller[#X_Rotation] "-Z_Rotation"

	
	
	in coordsys local with animate on
	(
		at time 10 move body [0,60,0]
		at time 20 rotate body (eulerangles 0 0 0)
		at time 30 rotate body (eulerangles 0 0 40)
		at time 30 move body [5,15,0]
		at time 40 move body [0,80,0]
		at time 50 move body [0,-100,0]
		at time 50 rotate body (eulerangles 0 0 40)
		at time 70 rotate body (eulerangles 0 0 120)
		at time 70 move body [0,0,0]
		at time 90 move body [0,80,0]
	)
	
	select body
) 

any one else has any ideas how to approach this better ?

i’ve reviewed my previous code. actually it was not correct… this is a better version:


with redraw off
(
	delete objects

	spinAttrib = attributes "spinAttrib"
	(
		parameters main 
		(
			lastTM type:#matrix3 animatable:off
			angle type:#float animatable:off
		)
	)
	fn makeWheel name: radius: pos: wirecolor: = 
	(
		in (p = point name:name pos:pos size:10 wirecolor:yellow)
		(
			w = cylinder name:(name + "_body") sides:24 segments:1 radius:radius height:3 slice:on sliceFrom:350 sliceTo:10 pos:pos wirecolor:wirecolor
			w.objectOffsetRot = eulerangles 90 0 0
			CenterObject w
		)
		p
	)
	mapped fn makeWheelScript p =
	(
		node = p.children[1]
		
		ss  = "tm = parent.transform*(inverse this.lastTM)
" 
		ss += "sign = (if dot tm[1] this.lastTM[1] > 0 then 1 else -1)
" 
		ss += "this.angle += 360*tm.pos.x*sign/(2*pi*radius)
"
		ss += "this.lastTM = parent.transform
"
		ss += "degtorad(this.angle)
"

		c = node.rotation.controller[2].controller = float_script()
		custattributes.add c spinAttrib
		c.lastTM = p.transform
		c.addconstant "radius" node.radius
		c.addnode "parent" p
		
		c.setexpression ss
		c
	)
	body = 
	(
		b =  (box name:"Wheel_chair" width:25 length:20 height:25 pos:[-5,0,17] wirecolor:blue) - (c = box width:30 length:25 height:25 pos:[0,0,25])
		delete c
		b
	)
	local wheels = #()
	in body 
	(
		append wheels (makeWheel name:"LF_wheel" radius:5 pos:[10,-10,5] wirecolor:red)
		append wheels (makeWheel name:"RF_wheel" radius:5 pos:[10,10,5] wirecolor:red)
		append wheels (makeWheel name:"LR_wheel" radius:15 pos:[-10,-13,15] wirecolor:orange)
		append wheels (makeWheel name:"RR_wheel" radius:15 pos:[-10,13,15] wirecolor:orange)
	)	
	makeWheelScript wheels
	
	in coordsys local with animate on
	(
		at time 30 move body [60,0,0]
		at time 30 rotate body (eulerangles 0 0 0)
		at time 40 rotate body (eulerangles 0 0 -40)
		at time 40 move body [15,5,0]
		at time 70 move body [80,0,0]
		at time 70 rotate body (eulerangles 0 0 0)
		at time 80 rotate body (eulerangles 0 0 -40)
		at time 100 move body [-100,0,0]
	)
	
	select body
)

thanks!!
looks like its working very well
im having a bit of trouble replicating it on my rig
but im sure ill figure it out eventually
thanks again that was very helpfull

Page 2 / 2