View Full Version : move one object by moving another

04 April 2008, 03:48 PM
I know this is a real basic question but I can't seem to figure it out.

Say you have two boxes. With a script how do you make it so that when you move one box along y it makes the other box move up and down along x on a sin wave?

I am trying to do this in real time so that when I move the one box along y with the mouse I get these results. I don't want to have to key.

I tried a position controller but that doesn't seem to work in real time. What am I missing?

04 April 2008, 05:28 PM
what you're looking for is one of...
- parameter wiring
- expression controller
- script controller

Attached is an example with a script controller. Move the text up and down to make the box move straight horizontally, and in a sine wave vertically. In track view, open the properties of Box02's X and Y position tracks to see what it does.

04 April 2008, 09:19 PM
Thats what I was looking for!

Now the real question and I apologize if I am asking too much, but how do you write a script that would do that. I can't seem to figure out the right expression and when I look up the expression controler in the maxscript reference it doesn't make that much sense to the only thing that it can accept a string for it's expression?

Thank you so much for your help.

04 April 2008, 10:14 PM
Here's a script_controller version of what you're after...
-- create two objects
b = box()
b2 = box pos:[50,50,25]
-- create a variable holding the difference in the two positions
offset = b.pos - b2.pos
-- create a point to hold the script, then create the script
p = point()
fs = float_script()
p.position.z_position.controller = fs
fs.addNode "cube1" b
fs.addNode "cube2" b2
fs.script = "cube2.pos = cube1.pos - offset\n 0" /* the zero
is tacked on at the end because float script needs to return a float */

04 April 2008, 10:59 PM
ParamWire version...
b = box()
b2 = box pos:[50,50,25]
paramWire.connect2way b.pos.controller[#x_position]\
b2.pos.controller[#x_position] ("x_position")("X_Position + 50")
paramWire.connect2way b.pos.controller[#y_position] \
b2.pos.controller[#y_position] ("y_position")("y_Position + 50")
paramWire.connect2way b.pos.controller[#z_position] \
b2.pos.controller[#z_position] ("z_position")("z_Position + 25")

04 April 2008, 11:03 PM
in the script version... what happens when you restart max and reload the file? Doesn't the "offset" variable get lost? You'd have to make it a global variable :) Better to add it as a variable to the controller?

Also.. no sine wave motion - but that should be easy enough to add.

Now an expression controller version? ;)

04 April 2008, 11:11 PM
Read some of my other posts, ZB; I'm pushing my limits as it is. :)

04 April 2008, 01:07 PM
Awesome! Thank you both so much for your help! Exactly what I was looking for.

CGTalk Moderation
04 April 2008, 01:07 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.