Forum Groups
  All forums
    Help & Feedback
      Questions
      Work in progress
      Finished Art
      Non-Max related
    Community
      Offtopic
      News
    Hardware
    Photography


Featured Threads
  inspiration alert!!!
(36 replies)
  Indespensible MaxScripts, Plugins and 3rd Party Tools
(37 replies)
  The allmighty FREE Resources Thread !
(17 replies)
  spam alert!!!
(4886 replies)
  Maxforums member photo gallery index
(114 replies)
  Maxforums Member Tutorials
(89 replies)
  three cheers to maxforums...
(240 replies)
  101 Things you didnt know in Max...
(198 replies)
  A Face tutorial from MDB101 :D
(95 replies)
  Maxforums.org Members Gallery
(516 replies)
  SON OF POST YOURSELF
(637 replies)
  Dub's Maxscript Tutorial Index
(119 replies)

Maxunderground news unavailable

Expressions - Move one object based on another's position, with threshold
show user profile  Loud
I have two objects. How can I make object B move based on A's movement only when it gets past a certain threshold?

For example if A is higher on the Y axis than B, I want it so that when A travels lower on the Y axis than B I want B to travel with A as it continues to go lower.

A limit controller won't suffice as I need to do this via an expression so that other things can update based upon this action.

Here is an example using the limit controller, I just want to do the same thing with an expression.





read 663 times
3/4/2009 10:16:59 PM (last edit: 3/4/2009 10:19:59 PM)
show user profile  Toen
Hi Loud,
I tested this it out and seems to work the way you want.

In the y controller slot of Object B assign a Script Controller and put this code into it:

if (Obj_A.pos.y<threshold) then (
Obj_A.pos.y-Obj_A_To_Obj_B_Offset
) else (
Obj_B.pos.y
)


Use 'Assign Node' to assign the objects in the scene to their respective Obj_A and Obj_B variables.
And use 'Assign Constant' to assign the desired values to 'threshold' and 'Obj_A_To_Obj_B_Offset'
Or you could just put number values in place of those last two variables in the above scripts.
'Threshold' is the location along the y-axis where Obj_A begins to influence Obj_B
'Obj_A_To_Obj_B_Offset' is the distance to maintain between the two objects when Obj_A influences Obj_B
read 614 times
3/5/2009 2:55:07 PM (last edit: 3/5/2009 2:57:58 PM)
show user profile  Loud
Thanks a mill Toen I can't wait to try it out.

I'm dumbfounded at the moment because what you did looks almost exactly the same as was what I was trying to do during lunch, but I couldn't get it to work.

I'll compare when I get home, it might be some syntax thing as I work as a programmer, but I'm just starting to get into maxscript.

[Edit:]
From memory here is what I was doing in the Script Controller for the Y (just as an experiment to limit a box's movement)

if ($Box01.pos.y > 100) do
(
$Box01.pos.y = 100
)
else
(
$Box01.pos.y
)

Again... probably the wrong way to do things...


read 597 times
3/5/2009 3:36:29 PM (last edit: 3/5/2009 3:41:12 PM)
show user profile  MrBurns
Edit: nevermind *clicks invisible "delete post" button*
read 572 times
3/6/2009 12:36:49 AM (last edit: 3/6/2009 12:37:41 AM)
show user profile  Loud
I got it to behave in an acceptable, but not ideal way. I think my problem is that when writing an expression for an object's controller, you can't reference the object itself when setting a property (as I do in my example above). There has to be a way to do this!


read 553 times
3/6/2009 8:40:10 AM (last edit: 3/6/2009 8:41:41 AM)
show user profile  Toen
Try using the 'Assign Node' method I mentioned above :)
read 538 times
3/6/2009 11:52:30 PM (last edit: 3/6/2009 11:52:30 PM)
show user profile  Loud
Oh believe me I have. Whenever I try to assign a self referential property, it says there is a circular dependency.


read 536 times
3/7/2009 12:04:08 AM (last edit: 3/7/2009 12:04:08 AM)
show user profile  Garp
Just a syntax thing.

For a simple test, you can use either
if boolean do expression
or
if boolean then expression

To add an else, you need to use the if ... then ... form.
if ... do ... else ... doesn't work.




read 532 times
3/7/2009 12:20:01 AM (last edit: 3/7/2009 12:20:01 AM)
show user profile  Toen
Should work, see up above where it says 'Obj_B.pos.y' that is a self-reference. Can you show the code you are using when it's using the 'Assign Node' option?

Here's an example of what I did with code above:



read 513 times
3/7/2009 4:23:19 AM (last edit: 3/7/2009 4:25:33 AM)
show user profile  Loud
Sorry, I don't think I'm being clear. What I want to do is in addition to what I described earlier. The problem I'm having with a is trying to set a self-referential property, not get. I can do what your video and my earlier one show just fine, I've moved on to a separate but similar problem.

I can move Obj_A based on Obj_B, but I also want to limit Obj_A based on Obj_A's position.

Essentially what I want to do now is limit the object's movement like a limit controller can, but through an expression. The only way I've seen this done so far is using a two-way wire controller with some funky math to keep the master / slave within the limits. The low Max character rig does it that way.

The concept seems simple to me, and I can't understand why I can't do it via expression. I want to limit my position, based on my position. This is the expression I put on a box's Y position script controller:

if (box.pos.y > 100) then
100
) else (
box.pos.y
)

Essentially limiting the box position to < 100. I use assign node to assign box to reference myself, click Evaluate and get "Unknown system exception".

If I set the expression to simply:

box.pos.y

Then I can move the box, but every time I move the box in the Y direction, it "resets" to it's last Y position.

If this is an exercise in insanity I apologize, I'm just trying to learn the dos and don'ts here....


read 494 times
3/7/2009 9:30:27 AM (last edit: 3/7/2009 9:33:46 AM)
show user profile  Toen
Hmm odd.

I put this in Obj B's code as well and left Obj A's controllers as bezier floats, no script controllers:

if Obj_A.pos.y>70 then Obj_A.pos.y=70 else Obj_A.pos.y=Obj_A.pos.y

Place it in line above/before Obj B's code and it restricts Obj A to above reqluirement but doesn't show it as such until you let go of the mouse drag. Well it shows it in regard to the objects pivot point but the mesh still follows the mouse draging past the limiting point.
read 484 times
3/7/2009 10:18:41 AM (last edit: 3/7/2009 10:19:17 AM)
#Maxforums IRC
Open chat window


Support Maxforums.org