View Full Version : object limits..can it be done.
10-14-2003, 09:24 PM
I'm trying to set up limits for the movement of an object.
Eg. -5 to 5 on X and -5 to 5 on Y.
I need to be able to freely move the object within the area mentioned above but have it so the object cannot move outside of the -5 to 5 ranges.
Is this possible? I'm really struggling to find a way to do this.
Cheers for any help
10-15-2003, 07:46 PM
Yes, it's possible. You only need a position script controller where you constrain the object to that region.
Problem 1:Max doesn't allow selfreference in script controllers. So you need to fool it.
For example you can create a dummy, apply a position script controller to it and then do the constraint check. Something like this
If($objectname.pos.x>5) then $objectname.x=5
If($objectname.pos.x<-5) then $objectname.pos.x=-5
If($objectname.pos.y>5) then $objectname.pos.y=5
If($objectname.pos.y<-5) then $objectname.posy=-5
[-123.188, 0, 0.483092]
The $objectname object is the object you want to constraint. The last line is the dummy position that appeared when entering at first to the properties of the script controller. Don't touch it
Problem2:The constraint is not reflected in real time, only when you move the slidertime. To solve this you need the
dependsOn $objectname directive placed in the firstline to to enable interactive update.
Check the .max (max 5)
10-15-2003, 09:31 PM
You are a star:thumbsup:
That problem has been bugging me for days and everyone I spoke to seemed to think it couldn't be done.
Thanks for that. I owe you one.
10-16-2003, 02:10 PM
Reality, do you know if the realtime update could be implemented maybe with a callback asociated to the dummy position?.
10-16-2003, 03:52 PM
fabman, using dependsOn $objectname you solve the realtime update problem ;)
10-16-2003, 07:36 PM
Yep, reality, I saw that on your first post, but it was just me thinking if it was posible to do it through any other way... thanx again.
10-20-2003, 08:46 AM
Is there a way to get the constraints to act at a local level?
I'd like to link the 'constrained' object(sphere01 in your test) so I can freely position it elsewhere. Then have the constraints work when I move sphere01 directly.
10-20-2003, 10:54 PM
It's possible, of course. It would be very easy using selfrerence, but as said you cannot(in max 6 this seems to work). So you have to indicate in some manner the base position where the distances will be calculated. From a nonscripter point of view the easiest way is using another helper(let's say a point) and put it in the base position you need.
Then alter the position script of the dummy with:
dependsOn $sphere01 $point01
If($point01.pos.x - $sphere01.pos.x >30) then $sphere01.pos.x=$point01.pos.x-30
Else If($point01.pos.x - $sphere01.pos.x <-30) then $sphere01.pos.x=$point01.pos.x+30
If($point01.pos.y - $sphere01.pos.y >30) then $sphere01.pos.y=$point01.pos.y-30
Else If($point01.pos.y - $sphere01.pos.y <-30) then $sphere01.pos.y=$point01.pos.y+30
[-123.188, 0, 0.483092]
I should have put those else with the other day example, but somewhat forgot it (if the first condition happens, sure the second won't, so no need to test it). You get the distances between the sphere and point and act consecuently. Tell us If you don't understand something
By the way, I remember when scripted the first example that the constraint was in real time(when the object arrived to one of the frontiers, it simply stopped). I reloaded the file I attached and saw that the gizmo stopped at the frontier but the object could go forward(when the click is finished the object returns to the gizmo position). Maybe I have touched something I shouldn't hehe
->Edit:Oh, i found the problem of the real time thing. I deactivated by accidentthe dual planes option of Viewport configuration.8) Now it works ok again
10-21-2003, 08:30 AM
Thanks once again.
I've been looking at a prerelease of Max6 and noticed the 'Local this' they have added.
Which will be very useful but I don't know when we are upgrading to 6 yet.
01-16-2006, 08:00 AM
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.
vBulletin v3.0.5, Copyright ©2000-2014, Jelsoft Enterprises Ltd.