[Closed] Linking angular motion to linear motion
Please picture a cylinder and a box. I’m trying to connect the two such that when the cylinder is rotated the box will move on the x-axis in a set increment, and when the box is moved on the x-axis the cylinder will rotate a set increment. I’ve tried wiring a two-way connection between the cylinder’s Z_Rotation (in both degrees and radians) and the box’s X_Position; moving the box rotates the cylinder, but when I try to rotate the cylinder either (a) the cylinder’s rotation is frozen, or (b) the box moves erratically.
Is this stunt something that should be done with wiring at all, or through constraints? Many thanks.
If you are NOT using any conversion, it should be running smoothly (it does here, tested in Max 2008).
If you DO want a conversion (because X would translate into very fast rotation without it), you have to do a conversion on BOTH SIDES!
So if you have wired the X_Position to the Z_Rotation bi-directionally, in the one expression you have to enter
radToDeg Z_Rotation
and in the other
degToRad X_Position
This makes sure that the values passed in both directions are identical. If you enter only the degToRad X_Position for the rotation value, rotating the cylinder (or teapot in my case, as it is more obvious thanks to the spout) at 360 degrees will move the box correctly but the cylinder itself will rotate only a small fraction of what the rotation gizmo shows. Similarly, if you convert only the radToDeg Z_Rotation but not the other expression, moving the box will cause a fast rotation of the cylinder, but rotating the cylinder can cause huge jumps in the X position of the box.
Perfect! In retrospect the degtoRad/radtoDeg thing is common sense… hmm, that’s somewhat self-incriminating.:rolleyes: Thanks again.
Man, it hasn’t been my day! When I manually wire two objects together ala the above technique, the connection is perfect. In trying to duplicate it in a rollout…
rollout wtest "Wire Test"
(
button btn_b1 "Make Box 1"
button btn_b2 "Make Box 2"
button btn_wire "Connect"
local b1, b2, amt
on btn_b1 pressed do
(
b1 = box()
)
on btn_b2 pressed do
(
b2 = box pos:[50,0,0]
)
on btn_wire pressed do
(
paramWire.connect2way b1.rotation.controller[#Z_Rotation]\
b2.pos.controller[#X_Position] ("radtoDeg Z_Rotation") \
("degtoRad X_Position")
)
)
createDialog wtest 200 100
… I get an “–Unable to convert: undefined to type:Float” exception. Where’s the doggone error?
-- Error occurred in __wire__()
-- Frame:
-- z_rotation: undefined
-- X_Position: 50.0
>> MAXScript Wire Controller Exception: -- Unable to convert: undefined to type: Float <<
You have to read 2 lines before what you writed:
“z_rotation: undefined”
So, there is no “z_rotation”
It’s better you start doing all the wire staff manually, then check the final controllers with MXS.
showProperties $box06.controller.rotation.controller[3] -- 3 for Z rotation
.numWires : integer
.isMaster : boolean
.isSlave : boolean
.isTwoWay : boolean
.slaveAnimation : control
.Z_Rotation_Animation : float
false
So, this is the value you are looking for:
$box06.controller.rotation.controller[3].Z_Rotation_Animation
Actually, I found that the problem was that I had the left-hand and right-hand expressions flipped.
-- This, what I originally had, throws an error
paramWire.connect2way b1.rotation.controller[#Z_Rotation]\
b2.pos.controller[#X_Position] "radtoDeg Z_Rotation" "degtoRad X_Position"
-- This works just fine
paramWire.connect2way b1.rotation.controller[#Z_Rotation]\
b2.pos.controller[#X_Position] "degtoRad X_Position" "radtoDeg Z_Rotation"